mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 01:15:00 -06:00
4.54 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
051769bbc5
commit
b82f80647d
@@ -5,40 +5,18 @@
|
||||
#include "Lang.h"
|
||||
#include "TextConfig.h"
|
||||
|
||||
#include "StdInStream.h"
|
||||
#include "../Windows/FileIO.h"
|
||||
#include "UTFConvert.h"
|
||||
#include "Defs.h"
|
||||
|
||||
/*
|
||||
static UInt32 HexStringToNumber(const char *string, int &finishPos)
|
||||
static bool HexStringToNumber(const UString &s, UInt32 &value)
|
||||
{
|
||||
UInt32 number = 0;
|
||||
for (finishPos = 0; finishPos < 8; finishPos++)
|
||||
{
|
||||
char c = string[finishPos];
|
||||
int a;
|
||||
if (c >= '0' && c <= '9')
|
||||
a = c - '0';
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
a = 10 + c - 'A';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
a = 10 + c - 'a';
|
||||
else
|
||||
return number;
|
||||
number *= 0x10;
|
||||
number += a;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
*/
|
||||
static bool HexStringToNumber(const UString &string, UInt32 &aResultValue)
|
||||
{
|
||||
aResultValue = 0;
|
||||
if (string.IsEmpty())
|
||||
value = 0;
|
||||
if (s.IsEmpty())
|
||||
return false;
|
||||
for (int i = 0; i < string.Length(); i++)
|
||||
for (int i = 0; i < s.Length(); i++)
|
||||
{
|
||||
wchar_t c = string[i];
|
||||
wchar_t c = s[i];
|
||||
int a;
|
||||
if (c >= L'0' && c <= L'9')
|
||||
a = c - L'0';
|
||||
@@ -48,17 +26,17 @@ static bool HexStringToNumber(const UString &string, UInt32 &aResultValue)
|
||||
a = 10 + c - L'a';
|
||||
else
|
||||
return false;
|
||||
aResultValue *= 0x10;
|
||||
aResultValue += a;
|
||||
value *= 0x10;
|
||||
value += a;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool WaitNextLine(const AString &string, int &pos)
|
||||
static bool WaitNextLine(const AString &s, int &pos)
|
||||
{
|
||||
for (;pos < string.Length(); pos++)
|
||||
if (string[pos] == 0x0A)
|
||||
for (; pos < s.Length(); pos++)
|
||||
if (s[pos] == 0x0A)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -70,19 +48,29 @@ static int CompareLangItems(void *const *elem1, void *const *elem2, void *)
|
||||
return MyCompare(langPair1.Value, langPair2.Value);
|
||||
}
|
||||
|
||||
bool CLang::Open(LPCTSTR fileName)
|
||||
bool CLang::Open(LPCWSTR fileName)
|
||||
{
|
||||
_langPairs.Clear();
|
||||
CStdInStream file;
|
||||
NWindows::NFile::NIO::CInFile file;
|
||||
if (!file.Open(fileName))
|
||||
return false;
|
||||
AString string;
|
||||
file.ReadToString(string);
|
||||
UInt64 length;
|
||||
if (!file.GetLength(length))
|
||||
return false;
|
||||
if (length > (1 << 20))
|
||||
return false;
|
||||
AString s;
|
||||
char *p = s.GetBuffer((int)length + 1);
|
||||
UInt32 processed;
|
||||
if (!file.Read(p, (UInt32)length, processed))
|
||||
return false;
|
||||
p[(UInt32)length] = 0;
|
||||
s.ReleaseBuffer();
|
||||
file.Close();
|
||||
int pos = 0;
|
||||
if (string.Length() >= 3)
|
||||
if (s.Length() >= 3)
|
||||
{
|
||||
if (Byte(string[0]) == 0xEF && Byte(string[1]) == 0xBB && Byte(string[2]) == 0xBF)
|
||||
if (Byte(s[0]) == 0xEF && Byte(s[1]) == 0xBB && Byte(s[2]) == 0xBF)
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
@@ -90,15 +78,15 @@ bool CLang::Open(LPCTSTR fileName)
|
||||
// read header
|
||||
|
||||
AString stringID = ";!@Lang@!UTF-8!";
|
||||
if (string.Mid(pos, stringID.Length()) != stringID)
|
||||
if (s.Mid(pos, stringID.Length()) != stringID)
|
||||
return false;
|
||||
pos += stringID.Length();
|
||||
|
||||
if (!WaitNextLine(string, pos))
|
||||
if (!WaitNextLine(s, pos))
|
||||
return false;
|
||||
|
||||
CObjectVector<CTextConfigPair> pairs;
|
||||
if (!GetTextConfig(string.Mid(pos), pairs))
|
||||
if (!GetTextConfig(s.Mid(pos), pairs))
|
||||
return false;
|
||||
|
||||
_langPairs.Reserve(_langPairs.Size());
|
||||
|
||||
@@ -17,7 +17,7 @@ class CLang
|
||||
{
|
||||
CObjectVector<CLangPair> _langPairs;
|
||||
public:
|
||||
bool Open(LPCTSTR fileName);
|
||||
bool Open(LPCWSTR fileName);
|
||||
void Clear() { _langPairs.Clear(); }
|
||||
int FindItem(UInt32 value) const;
|
||||
bool GetMessage(UInt32 value, UString &message) const;
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../Windows/FileIO.h"
|
||||
|
||||
#include "ListFileUtils.h"
|
||||
#include "StdInStream.h"
|
||||
#include "StringConvert.h"
|
||||
#include "UTFConvert.h"
|
||||
|
||||
@@ -15,14 +16,25 @@ static void RemoveQuote(UString &s)
|
||||
s = s.Mid(1, s.Length() - 2);
|
||||
}
|
||||
|
||||
bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &resultStrings, UINT codePage)
|
||||
bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)
|
||||
{
|
||||
CStdInStream file;
|
||||
NWindows::NFile::NIO::CInFile file;
|
||||
if (!file.Open(fileName))
|
||||
return false;
|
||||
|
||||
UInt64 length;
|
||||
if (!file.GetLength(length))
|
||||
return false;
|
||||
if (length > ((UInt32)1 << 31))
|
||||
return false;
|
||||
AString s;
|
||||
file.ReadToString(s);
|
||||
char *p = s.GetBuffer((int)length + 1);
|
||||
UInt32 processed;
|
||||
if (!file.Read(p, (UInt32)length, processed))
|
||||
return false;
|
||||
p[(UInt32)length] = 0;
|
||||
s.ReleaseBuffer();
|
||||
file.Close();
|
||||
|
||||
UString u;
|
||||
#ifdef CP_UTF8
|
||||
if (codePage == CP_UTF8)
|
||||
@@ -43,7 +55,7 @@ bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &resultStrings, UINT
|
||||
for(int i = 0; i < u.Length(); i++)
|
||||
{
|
||||
wchar_t c = u[i];
|
||||
if (c == L'\n')
|
||||
if (c == L'\n' || c == 0xD)
|
||||
{
|
||||
t.Trim();
|
||||
RemoveQuote(t);
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
#include "MyString.h"
|
||||
#include "Types.h"
|
||||
|
||||
bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
|
||||
bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -75,7 +75,7 @@ bool CStdInStream::Eof()
|
||||
|
||||
int CStdInStream::GetChar()
|
||||
{
|
||||
int c = getc(_stream);
|
||||
int c = fgetc(_stream); // getc() doesn't work in BeOS?
|
||||
if(c == EOF && !Eof())
|
||||
throw kReadErrorMessage;
|
||||
return c;
|
||||
|
||||
Reference in New Issue
Block a user