summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-07-18 19:29:31 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-07-18 19:29:36 +0300
commit004641be43a542a04e8cabdaca8fe8a4706a4b17 (patch)
treed3025d9fc34e44e138ee787a8eeaeff704d9b6c3
parent13a280bbca0ac4a75562e35b283f22e238976bda (diff)
old perversion with pointer type conversion removed
-rw-r--r--src/mir_app/mir_app.vcxproj1
-rw-r--r--src/mir_app/mir_app.vcxproj.filters3
-rw-r--r--src/mir_app/src/file.cpp32
-rw-r--r--src/mir_app/src/file.h5
-rw-r--r--src/mir_app/src/fileutils.cpp39
-rw-r--r--src/mir_app/src/filexferdlg.cpp28
6 files changed, 66 insertions, 42 deletions
diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj
index 2610d0ef02..c0855b8ea5 100644
--- a/src/mir_app/mir_app.vcxproj
+++ b/src/mir_app/mir_app.vcxproj
@@ -82,6 +82,7 @@
<ClCompile Include="src\fileopts.cpp" />
<ClCompile Include="src\filerecvdlg.cpp" />
<ClCompile Include="src\filesenddlg.cpp" />
+ <ClCompile Include="src\fileutils.cpp" />
<ClCompile Include="src\filexferdlg.cpp" />
<ClCompile Include="src\filter.cpp" />
<ClCompile Include="src\findadd.cpp" />
diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters
index a73e0dfbd4..69928a983f 100644
--- a/src/mir_app/mir_app.vcxproj.filters
+++ b/src/mir_app/mir_app.vcxproj.filters
@@ -425,6 +425,9 @@
<ClCompile Include="src\ftmanager.cpp">
<Filter>Source Files\File</Filter>
</ClCompile>
+ <ClCompile Include="src\fileutils.cpp">
+ <Filter>Source Files\File</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\filter.h">
diff --git a/src/mir_app/src/file.cpp b/src/mir_app/src/file.cpp
index 5d55c3e9d0..2e221cb9f6 100644
--- a/src/mir_app/src/file.cpp
+++ b/src/mir_app/src/file.cpp
@@ -28,9 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
MWindowList g_hFileWindows;
HANDLE hDlgSucceeded, hDlgCanceled;
-wchar_t* PFTS_StringToTchar(int flags, const wchar_t* s);
-int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS* ft, const wchar_t* s, wchar_t *r);
-
CMOption<bool> File::bAutoMin(SRFILEMODULE, "AutoMin", false);
CMOption<bool> File::bAutoClear(SRFILEMODULE, "AutoClear", true);
CMOption<bool> File::bAutoClose(SRFILEMODULE, "AutoClose", false);
@@ -198,13 +195,16 @@ void FreeProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *fts)
void CopyProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src)
{
*dest = *src;
- if (src->szCurrentFile.w) dest->szCurrentFile.w = PFTS_StringToTchar(src->flags, src->szCurrentFile.w);
+ if (src->szCurrentFile.w) dest->szCurrentFile.w = PFTS_StringToTchar(src->flags, src->szCurrentFile);
if (src->pszFiles.w) {
dest->pszFiles.w = (wchar_t**)mir_alloc(sizeof(wchar_t*)*src->totalFiles);
- for (int i = 0; i < src->totalFiles; i++)
- dest->pszFiles.w[i] = PFTS_StringToTchar(src->flags, src->pszFiles.w[i]);
+ for (int i = 0; i < src->totalFiles; i++) {
+ MAllStrings s = { src->pszFiles.a[i] };
+ dest->pszFiles.w[i] = PFTS_StringToTchar(src->flags, s);
+ }
}
- if (src->szWorkingDir.w) dest->szWorkingDir.w = PFTS_StringToTchar(src->flags, src->szWorkingDir.w);
+ if (src->szWorkingDir.w)
+ dest->szWorkingDir.w = PFTS_StringToTchar(src->flags, src->szWorkingDir);
dest->flags &= ~PFTS_UTF;
dest->flags |= PFTS_UNICODE;
}
@@ -222,14 +222,16 @@ void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANS
if (src->pszFiles.w) {
if (!dest->pszFiles.w)
dest->pszFiles.w = (wchar_t**)mir_calloc(sizeof(wchar_t*)*src->totalFiles);
- for (int i = 0; i < src->totalFiles; i++)
- if (!dest->pszFiles.w[i] || !src->pszFiles.w[i] || PFTS_CompareWithTchar(src, src->pszFiles.w[i], dest->pszFiles.w[i])) {
+ for (int i = 0; i < src->totalFiles; i++) {
+ MAllStrings fname; fname.w = src->pszFiles.w[i];
+ if (!dest->pszFiles.w[i] || !fname.w || PFTS_CompareWithTchar(src, fname, dest->pszFiles.w[i])) {
mir_free(dest->pszFiles.w[i]);
- if (src->pszFiles.w[i])
- dest->pszFiles.w[i] = PFTS_StringToTchar(src->flags, src->pszFiles.w[i]);
+ if (fname.w)
+ dest->pszFiles.w[i] = PFTS_StringToTchar(src->flags, fname);
else
dest->pszFiles.w[i] = nullptr;
}
+ }
}
else if (dest->pszFiles.w) {
for (int i = 0; i < dest->totalFiles; i++)
@@ -241,18 +243,18 @@ void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANS
dest->currentFileNumber = src->currentFileNumber;
dest->totalBytes = src->totalBytes;
dest->totalProgress = src->totalProgress;
- if (src->szWorkingDir.w && (!dest->szWorkingDir.w || PFTS_CompareWithTchar(src, src->szWorkingDir.w, dest->szWorkingDir.w))) {
+ if (src->szWorkingDir.w && (!dest->szWorkingDir.w || PFTS_CompareWithTchar(src, src->szWorkingDir, dest->szWorkingDir.w))) {
mir_free(dest->szWorkingDir.w);
if (src->szWorkingDir.w)
- dest->szWorkingDir.w = PFTS_StringToTchar(src->flags, src->szWorkingDir.w);
+ dest->szWorkingDir.w = PFTS_StringToTchar(src->flags, src->szWorkingDir);
else
dest->szWorkingDir.w = nullptr;
}
- if (!dest->szCurrentFile.w || !src->szCurrentFile.w || PFTS_CompareWithTchar(src, src->szCurrentFile.w, dest->szCurrentFile.w)) {
+ if (!dest->szCurrentFile.w || !src->szCurrentFile.w || PFTS_CompareWithTchar(src, src->szCurrentFile, dest->szCurrentFile.w)) {
mir_free(dest->szCurrentFile.w);
if (src->szCurrentFile.w)
- dest->szCurrentFile.w = PFTS_StringToTchar(src->flags, src->szCurrentFile.w);
+ dest->szCurrentFile.w = PFTS_StringToTchar(src->flags, src->szCurrentFile);
else
dest->szCurrentFile.w = nullptr;
}
diff --git a/src/mir_app/src/file.h b/src/mir_app/src/file.h
index ee248814ff..17456425eb 100644
--- a/src/mir_app/src/file.h
+++ b/src/mir_app/src/file.h
@@ -142,3 +142,8 @@ namespace File
extern CMOption<uint32_t> iOfflineSize;
extern CMOption<wchar_t*> wszSaveDir, wszScanCmdLine;
};
+
+// fieutils.c
+
+wchar_t *PFTS_StringToTchar(int flags, const MAllStrings s);
+int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS *ft, const MAllStrings s, wchar_t *r);
diff --git a/src/mir_app/src/fileutils.cpp b/src/mir_app/src/fileutils.cpp
new file mode 100644
index 0000000000..3533e74c42
--- /dev/null
+++ b/src/mir_app/src/fileutils.cpp
@@ -0,0 +1,39 @@
+/*
+
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+wchar_t* PFTS_StringToTchar(int flags, const MAllStrings s)
+{
+ if (flags & PFTS_UTF)
+ return mir_utf8decodeW(s.a);
+ if (flags & PFTS_UNICODE)
+ return mir_wstrdup(s.w);
+ return mir_a2u(s.a);
+}
+
+int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS *ft, const MAllStrings s, wchar_t *r)
+{
+ if (ft->flags & PFTS_UTF)
+ return mir_wstrcmp(Utf2T(s.a), r);
+
+ if (ft->flags & PFTS_UNICODE)
+ return mir_wstrcmp(s.w, r);
+
+ return mir_wstrcmp(_A2T(s.a), r);
+}
diff --git a/src/mir_app/src/filexferdlg.cpp b/src/mir_app/src/filexferdlg.cpp
index e7fc5e6d4c..fabac20dc7 100644
--- a/src/mir_app/src/filexferdlg.cpp
+++ b/src/mir_app/src/filexferdlg.cpp
@@ -47,32 +47,6 @@ struct virusscanthreadstartinfo
HWND hwndReply;
};
-wchar_t* PFTS_StringToTchar(int flags, const wchar_t *s)
-{
- if (flags & PFTS_UTF)
- return mir_utf8decodeW((char*)s);
- if (flags & PFTS_UNICODE)
- return mir_wstrdup(s);
- return mir_a2u((char*)s);
-}
-
-int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS *ft, const wchar_t *s, wchar_t *r)
-{
- if (ft->flags & PFTS_UTF) {
- wchar_t *ts = mir_utf8decodeW((char*)s);
- int res = mir_wstrcmp(ts, r);
- mir_free(ts);
- return res;
- }
- if (ft->flags & PFTS_UNICODE)
- return mir_wstrcmp(s, r);
-
- wchar_t *ts = mir_a2u((char*)s);
- int res = mir_wstrcmp(ts, r);
- mir_free(ts);
- return res;
-}
-
static void SetOpenFileButtonStyle(HWND hwndButton, int enabled)
{
EnableWindow(hwndButton, enabled);
@@ -553,7 +527,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
if (dat->files == nullptr)
dat->files = (wchar_t **)mir_calloc((fts->totalFiles + 1) * sizeof(wchar_t *));
if (fts->currentFileNumber < fts->totalFiles && dat->files[fts->currentFileNumber] == nullptr)
- dat->files[fts->currentFileNumber] = PFTS_StringToTchar(fts->flags, fts->szCurrentFile.w);
+ dat->files[fts->currentFileNumber] = PFTS_StringToTchar(fts->flags, fts->szCurrentFile);
}
/* HACK: for 0.3.3, limit updates to around 1.1 ack per second */