summaryrefslogtreecommitdiff
path: root/updater/extern.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-29 02:54:40 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-29 02:54:40 +0000
commit8d2322e9200357df2fd873d385f99febad35effd (patch)
tree6f13ac4fe9999ca21192a054045c5b857a815e8b /updater/extern.cpp
parent3436bfa6059138bdb2007ae0a97a7d9d313e83c7 (diff)
set update url based on miranda's unicode status
allow ansi ver to read unicode dat file allow download of either version to replace either version (plugin name aliases) git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@305 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'updater/extern.cpp')
-rw-r--r--updater/extern.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/updater/extern.cpp b/updater/extern.cpp
index 81254cf..eaaeb36 100644
--- a/updater/extern.cpp
+++ b/updater/extern.cpp
@@ -267,7 +267,28 @@ void MoveFiles(HANDLE hLogFile, TCHAR *src_folder, TCHAR *dst_folder, TCHAR *bac
RemoveDirectory(src_folder);
}
+bool ReadTLine(HANDLE hDatFile, TCHAR *line, int bsize, int &offset) {
+ unsigned long bytes_read;
+ BOOL bResult;
+ while((bResult = ReadFile(hDatFile, line + offset, sizeof(TCHAR), &bytes_read, 0)) && offset < bsize && bytes_read == sizeof(TCHAR) && line[offset] && (line[offset] != _T('\n') || (offset > 0 && line[offset - 1] != _T('\r')))) offset++;
+
+#ifndef _UNICODE
+ if(offset == 1 && line[1] == 0) {
+ wchar_t wline[MAX_PATH];
+ wline[0] = *(wchar_t *)line;
+
+ while((bResult = ReadFile(hDatFile, wline + offset, sizeof(wchar_t), &bytes_read, 0)) && offset < bsize && bytes_read == sizeof(wchar_t) && wline[offset] && (wline[offset] != L'\n' || (offset > 0 && wline[offset - 1] != L'\r'))) offset++;
+ if(offset > 0) wline[offset - 1] = 0; // cut off /r/n
+
+ WideCharToMultiByte(CP_ACP, 0, wline, -1, line, bsize, 0, 0);
+ }
+#endif
+ if(offset > 0) line[offset - 1] = 0; // cut off /r/n
+ return true;
+}
+
extern "C" void __declspec(dllexport) CALLBACK ExternalUpdate(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) {
+ //MessageBox(0, _T("ExternalUpdate"), _T("Updater"), MB_OK);
HANDLE hDatFile = CreateFileA(lpszCmdLine, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
if(hDatFile == INVALID_HANDLE_VALUE) {
char msg[1024];
@@ -295,13 +316,11 @@ extern "C" void __declspec(dllexport) CALLBACK ExternalUpdate(HWND hwnd, HINSTAN
do {
offset = 0;
if(i == 2 || i == 3 || i == 6 || i == 7) {
- while((bResult = ReadFile(hDatFile, ans_line + offset, 1, &bytes_read, 0)) && offset < MAX_PATH && bytes_read == 1 && offset < MAX_PATH && ans_line[offset] && (ans_line[offset] != '\n' || (offset > 0 && ans_line[offset - 1] != '\r'))) offset++;
+ while((bResult = ReadFile(hDatFile, ans_line + offset, 1, &bytes_read, 0)) && offset < MAX_PATH && bytes_read == 1 && ans_line[offset] && (ans_line[offset] != '\n' || (offset > 0 && ans_line[offset - 1] != '\r'))) offset++;
if(offset > 0) ans_line[offset - 1] = 0; // cut off /r/n
//MessageBoxA(0, ans_line, "Read ANSI text line", MB_OK);
} else {
- while((bResult = ReadFile(hDatFile, line + offset, sizeof(TCHAR), &bytes_read, 0)) && offset < MAX_PATH && bytes_read == sizeof(TCHAR) && offset < MAX_PATH && line[offset] && (line[offset] != _T('\n') || (offset > 0 && line[offset - 1] != _T('\r')))) offset++;
- if(offset > 0) line[offset - 1] = 0; // cut off /r/n
- //MessageBox(0, line, _T("Read Unicode text line"), MB_OK);
+ ReadTLine(hDatFile, line, MAX_PATH, offset);
}
switch(i) {
case 0: _tcsncpy(mir_exe, line, MAX_PATH); break;