Skip to content

Commit a0ac661

Browse files
chore: do something make windows happy
1 parent fc6a014 commit a0ac661

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if(APPLE)
159159
POST_BUILD
160160
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/res/files"
161161
"$<TARGET_FILE_DIR:wxTools>/../Resources/files")
162-
else()
162+
elseif(LINUX)
163163
add_custom_command(
164164
TARGET wxTools
165165
POST_BUILD

src/Common/wxTools.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323
#include "iconv.h"
2424
#endif
2525

26+
wxString wxtMsAppLocalDataPath()
27+
{
28+
// The path is: C:\Users\<User>\AppData\Local\wxTools
29+
wxString path = wxStandardPaths::Get().GetUserLocalDataDir();
30+
31+
// Remove "/wxTools" from path, now the path is: C:\Users\<User>\AppData\Local
32+
path = path.BeforeLast(wxFileName::GetPathSeparator());
33+
34+
// Using Microsoft app path:
35+
// C:\Users\<User>\AppData\Local\Packages\50263Qsaker2018.wxTools_83fbcck3baqe6\LocalState
36+
const wxString appFlag = wxString("50263Qsaker2018.wxTools_83fbcck3baqe6");
37+
path += wxString(wxFileName::GetPathSeparator()) + wxString("Packages");
38+
path += wxString(wxFileName::GetPathSeparator()) + appFlag;
39+
40+
return path;
41+
}
42+
2643
void FailureWriter(const char *data, size_t size)
2744
{
2845
// Remove the settings file
@@ -34,11 +51,19 @@ void FailureWriter(const char *data, size_t size)
3451

3552
std::string LogPath()
3653
{
54+
#if defined(__WINDOWS__)
55+
#if defined(WXT_PORTABLE_EDITION)
3756
wxString path = GetSettingsPath();
3857
path += wxFileName::GetPathSeparator();
3958
path += wxString("..");
4059
path += wxFileName::GetPathSeparator();
4160
path += wxString("log");
61+
#else
62+
wxString path = wxtMsAppLocalDataPath();
63+
path += wxString(wxFileName::GetPathSeparator()) + wxString("LocalState");
64+
path += wxString(wxFileName::GetPathSeparator()) + wxString("log");
65+
#endif
66+
#endif
4267

4368
#if defined(WIN32)
4469
wxMkDir(path);
@@ -1133,11 +1158,24 @@ void SetComboBoxSectionByIntClientData(wxComboBox *comboBox, int clientDataValue
11331158

11341159
wxString GetSettingsPath()
11351160
{
1136-
#if defined(WXT_PORTABLE_EDITION) && defined(WIN32)
1161+
#if defined(__WINDOWS__)
1162+
#if defined(WXT_PORTABLE_EDITION)
11371163
wxString path = wxGetCwd() + wxFileName::GetPathSeparator() + wxString("conf");
11381164
#else
1165+
wxString path = wxtMsAppLocalDataPath();
1166+
path += wxString(wxFileName::GetPathSeparator()) + wxString("Settings");
1167+
path += wxString(wxFileName::GetPathSeparator()) + wxString("conf");
1168+
#endif
1169+
#endif
1170+
1171+
#if defined(__LINUX__)
11391172
wxString path = wxStandardPaths::Get().GetUserDataDir();
11401173
#endif
1174+
1175+
#if defined(__APPLE__)
1176+
wxString path = wxStandardPaths::Get().GetUserDataDir();
1177+
#endif
1178+
11411179
// Make full dir...
11421180
if (!wxDirExists(path)) {
11431181
#if defined(WIN32)

src/MainWindow.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ void MainWindow::InitMenuHelp(wxMenuBar* menuBar)
348348

349349
// if history file not found, ignore this menu item
350350
wxString historyFileName = GetHistoryFileName();
351+
#if defined(__WINDOWS__)
352+
{
353+
#else
351354
if (wxFileExists(historyFileName)) {
355+
#endif
352356
tmpId = wxtNewID();
353357
menuHelp->Append(tmpId, _("History"), _("Show the history of the application."));
354358
Bind(wxEVT_MENU, &MainWindow::DoShowHistory, this, tmpId);
@@ -510,12 +514,18 @@ void MainWindow::DoCheckForUpdates(wxCommandEvent&)
510514

511515
void MainWindow::DoShowHistory(wxCommandEvent&)
512516
{
517+
#if defined(__WINDOWS__)
518+
int len = 0;
519+
char* txt = wxLoadUserResource(wxString("HISTORY_TXT"), wxT("TEXT"), &len);
520+
wxString historyText = wxString::FromUTF8(txt, len);
521+
delete[] txt;
522+
#else
513523
wxString path = GetHistoryFileName();
514524
if (!wxFileExists(path)) {
515525
wxMessageBox(_("History file not found!"), _("Error"), wxOK | wxICON_ERROR);
516526
return;
517527
}
518-
528+
#endif
519529
wxDialog dlg(this, wxID_ANY, _("wxTools Release History"), wxDefaultPosition, wxSize(600, 400));
520530
dlg.SetIcon(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, wxSize(64, 64)));
521531
wxTextCtrl* textCtrl = new wxTextCtrl(&dlg,
@@ -524,7 +534,11 @@ void MainWindow::DoShowHistory(wxCommandEvent&)
524534
wxDefaultPosition,
525535
wxDefaultSize,
526536
wxTE_MULTILINE | wxTE_DONTWRAP | wxTE_READONLY);
537+
#if defined(__WINDOWS__)
538+
textCtrl->SetValue(historyText);
539+
#else
527540
textCtrl->LoadFile(path);
541+
#endif
528542
dlg.ShowModal();
529543
}
530544

wxTools.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
IDI_ICON1 ICON DISCARDABLE "wxTools.ico"
2+
HISTORY_TXT TEXT "res/files/history.txt"

0 commit comments

Comments
 (0)