static void RecordZero(UniFile::txtstats & txstats, Int64 offset)
{
++txstats.nzeros;
- if (txstats.first_zero == -1)
- txstats.first_zero = offset;
- txstats.last_zero = offset;
}
/**
int nlfs;
int ncrlfs;
int nzeros;
- Poco::Int64 first_zero; // byte offset, initially -1
- Poco::Int64 last_zero; // byte offset, initially -1
int nlosses;
txtstats() { clear(); }
- void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; first_zero = -1; last_zero = -1; }
+ void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; }
};
virtual const txtstats & GetTxtStats() const = 0;
};
/** @brief Known Unicode encodings. */
enum UNICODESET
+#if __cplusplus >= 201103L || _MSC_VER >= 1600
+ : char
+#endif
{
NONE = 0, /**< No unicode. */
UCS2LE, /**< UCS-2 / UTF-16 little endian. */
if (ch == 0)
{
++stats.nzeros;
- Int64 index = offset + (ptr - start);
- if (stats.first_zero == -1)
- stats.first_zero = index;
- stats.last_zero = index;
}
else if (ch == '\r')
{
#include "UnicodeString.h"
/**
- * @brief Convert file flags to string presentation.
- * This function converts file flags to a string presentation that can be
- * shown in the GUI.
- * @return File flags as a string.
- */
-String DiffFileFlags::ToString() const
-{
- String sflags;
-#ifdef _WIN32
- if (attributes & FILE_ATTRIBUTE_READONLY)
- sflags += _T("R");
- if (attributes & FILE_ATTRIBUTE_HIDDEN)
- sflags += _T("H");
- if (attributes & FILE_ATTRIBUTE_SYSTEM)
- sflags += _T("S");
- if (attributes & FILE_ATTRIBUTE_ARCHIVE)
- sflags += _T("A");
-#endif
- if ((coding & coding_mask) == UTF_8)
- sflags += _T("8");
- if ((coding & coding_mask) == UCS_2BE)
- sflags += _T("B");
- if ((coding & coding_mask) == UCS_2LE)
- sflags += _T("L");
- if ((coding & coding_mask) == UCS_4)
- sflags += _T("4");
- return sflags;
-}
-
-/**
* @brief Clears FileInfo data.
*/
void DiffFileInfo::ClearPartial()
#include "FileTextStats.h"
/**
- * @brief Class for fileflags and coding info.
- */
-struct DiffFileFlags : public FileFlags
-{
- /**
- * @brief Encodings supported.
- */
- enum
- {
- UTF_8 = 0x1000,
- UCS_4 = 0x2000,
- UCS_2BE = 0x3000,
- UCS_2LE = 0x4000,
- coding_mask = 0x7000,
- };
-
- unsigned coding; /**< Coding info for item */
- DiffFileFlags() : coding(0) { }
- String ToString() const;
-};
-
-
-/**
* @brief Information for file.
* This class expands DirItem class with encoding information and
* text stats information.
{
// data
bool bVersionChecked; /**< true if version string is up-to-date */
- DiffFileFlags flags; /**< file attributes */
FileTextEncoding encoding; /**< unicode or codepage info */
FileTextStats m_textStats; /**< EOL, zero-byte etc counts */
#include "TFile.h"
/**
+ * @brief Convert file flags to string presentation.
+ * This function converts file flags to a string presentation that can be
+ * shown in the GUI.
+ * @return File flags as a string.
+ */
+String FileFlags::ToString() const
+{
+ String sflags;
+#ifdef _WIN32
+ if (attributes & FILE_ATTRIBUTE_READONLY)
+ sflags += _T("R");
+ if (attributes & FILE_ATTRIBUTE_HIDDEN)
+ sflags += _T("H");
+ if (attributes & FILE_ATTRIBUTE_SYSTEM)
+ sflags += _T("S");
+ if (attributes & FILE_ATTRIBUTE_ARCHIVE)
+ sflags += _T("A");
+#endif
+ return sflags;
+}
+
+/**
* @brief Set filename and path for the item.
* @param [in] fullpath Full path to file to set to item.
*/
ctime = 0;
mtime = 0;
size = -1;
- bIsDir = false;
version.Clear();
flags.reset();
}
unsigned attributes; /**< Fileattributes for item */
FileFlags() : attributes(0) { }
void reset() { attributes = 0; } /// Reset fileattributes
+ String ToString() const;
};
/**
Poco::File::FileSize size; /**< file size in bytes, -1 means file does not exist*/
String filename; /**< filename for this item */
String path; /**< full path (excluding filename) for the item */
- bool bIsDir; /**< is this a directory item or file item? */
FileVersion version; /**< string of fixed file version, eg, 1.2.3.4 */
FileFlags flags; /**< file attributes */
- DirItem() : ctime(0), mtime(0), size(-1), bIsDir(false) { }
+ DirItem() : ctime(0), mtime(0), size(-1) { }
void SetFile(const String &fullPath);
String GetFile() const;
bool Update(const String &sFilePath);
continue;
DirItem ent;
- ent.bIsDir = bIsDirectory;
ent.ctime = it->created();
if (ent.ctime < 0)
ent.ctime = 0;
ent.mtime = it->getLastModified();
if (ent.mtime < 0)
ent.mtime = 0;
-
- if (ent.bIsDir)
- ent.size = -1; // No size for directories
- else
- ent.size = it->getSize();
-
+ ent.size = it->getSize();
ent.path = sDir;
ent.filename = ucr::toTString(it.name());
#ifdef _WIN32
continue;
DirItem ent;
- ent.bIsDir = !!bIsDirectory;
// Save filetimes as seconds since January 1, 1970
// Note that times can be < 0 if they are around that 1970..
*/
static String ColAttrGet(const CDiffContext *, const void *p)
{
- const DiffFileFlags &r = *static_cast<const DiffFileFlags *>(p);
+ const FileFlags &r = *static_cast<const FileFlags *>(p);
return r.ToString();
}
*/
static int ColAttrSort(const CDiffContext *, const void *p, const void *q)
{
- const DiffFileFlags &r = *static_cast<const DiffFileFlags *>(p);
- const DiffFileFlags &s = *static_cast<const DiffFileFlags *>(q);
+ const FileFlags &r = *static_cast<const FileFlags *>(p);
+ const FileFlags &s = *static_cast<const FileFlags *>(q);
return r.ToString() == s.ToString();
}
unsigned nlfs; /**< Count of Unix (LF-byte) EOLs. */
unsigned ncrlfs; /**< Count of DOS (CR+LF-bytes) EOLs. */
unsigned nzeros; /**< Count of zero-bytes. */
- Poco::Int64 first_zero; /**< Byte offset to first zero-byte, initially -1 */
- Poco::Int64 last_zero; /**< Byte offset to last zero-byte, initially -1 */
- unsigned nlosses;
FileTextStats() { clear(); }
- void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; first_zero = -1; last_zero = -1; }
+ void clear() { ncrs = nlfs = ncrlfs = nzeros = 0; }
};
* @brief Default constructor.
*/
FileVersion::FileVersion()
-: m_bFileVersionSet(false)
-, m_fileVersionMS(0)
-, m_fileVersionLS(0)
-, m_bProductVersionSet(false)
-, m_productVersionMS(0)
-, m_productVersionLS(0)
+: m_fileVersionMS(0xffffffff)
+, m_fileVersionLS(0xffffffff)
{
}
*/
void FileVersion::Clear()
{
- m_bFileVersionSet = false;
- m_fileVersionMS = 0;
- m_fileVersionLS = 0;
- m_bProductVersionSet = false;
- m_productVersionMS = 0;
- m_productVersionLS = 0;
+ m_fileVersionMS = m_fileVersionLS = 0xffffffff;
}
/**
*/
void FileVersion::SetFileVersion(unsigned versionMS, unsigned versionLS)
{
- m_bFileVersionSet = true;
m_fileVersionMS = versionMS;
m_fileVersionLS = versionLS;
}
/**
- * @brief Set product version number.
- * @param [in] versionMS Most significant dword for version.
- * @param [in] versionLS Least significant dword for version.
- */
-void FileVersion::SetProductVersion(unsigned versionMS, unsigned versionLS)
-{
- m_bProductVersionSet = true;
- m_productVersionMS = versionMS;
- m_productVersionLS = versionLS;
-}
-
-/**
* @brief Get file version as a string.
* @return File version number as a string. Returns empty string if there is
* no version number for the file.
*/
String FileVersion::GetFileVersionString()
{
- if (!m_bFileVersionSet)
+ if (m_fileVersionMS == 0xffffffff && m_fileVersionLS == 0xffffffff)
return _T("");
return string_format(_T("%u.%u.%u.%u"), HIWORD(m_fileVersionMS),
LOWORD(m_fileVersionLS));
}
-/**
- * @brief Get product version as a string.
- * @return Product version number as a string.
- */
-String FileVersion::GetProductVersionString()
-{
- if (!m_bProductVersionSet)
- return _T("0.0.0.0");
-
- return string_format(_T("%u.%u.%u.%u"), HIWORD(m_productVersionMS),
- LOWORD(m_productVersionMS), HIWORD(m_productVersionLS),
- LOWORD(m_productVersionLS));
-}
class FileVersion
{
private:
- bool m_bFileVersionSet; //*< Is file version set? */
- bool m_bProductVersionSet; //*< Is product version set? */
unsigned m_fileVersionMS; //*< File version most significant dword. */
unsigned m_fileVersionLS; //*< File version least significant dword. */
- unsigned m_productVersionMS; //*< Product version most significant dword. */
- unsigned m_productVersionLS; //*< Product version least significant dword. */
public:
FileVersion();
void Clear();
void SetFileVersion(unsigned versionMS, unsigned versionLS);
- void SetProductVersion(unsigned versionMS, unsigned versionLS);
-
String GetFileVersionString();
- String GetProductVersionString();
};
#endif // _FILE_VERSION_H_
FileVersion version;\r
EXPECT_EQ(_T(""), version.GetFileVersionString());\r
}\r
- TEST_F(FileVersionTest, getprodver_notset)\r
- {\r
- FileVersion version;\r
- EXPECT_EQ(_T("0.0.0.0"), version.GetProductVersionString());\r
- }\r
\r
TEST_F(FileVersionTest, getfilever_zeros)\r
{\r
EXPECT_EQ(_T("1.2.3.4"), version.GetFileVersionString());\r
}\r
\r
- TEST_F(FileVersionTest, getprodver_zeros)\r
- {\r
- FileVersion version;\r
- version.SetProductVersion(0, 0);\r
- EXPECT_EQ(_T("0.0.0.0"), version.GetProductVersionString());\r
- }\r
-\r
- TEST_F(FileVersionTest, getprodver_simple1)\r
- {\r
- FileVersion version;\r
- version.SetProductVersion(1, 2);\r
- EXPECT_EQ(_T("0.1.0.2"), version.GetProductVersionString());\r
- }\r
- TEST_F(FileVersionTest, getprodver_real)\r
- {\r
- FileVersion version;\r
- DWORD hi = (1 << 16) | 2;\r
- DWORD lo = (3 << 16) | 4;\r
- version.SetProductVersion(hi, lo);\r
- EXPECT_EQ(_T("1.2.3.4"), version.GetProductVersionString());\r
- }\r
-\r
} // namespace\r