aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthexai <58434170+thexai@users.noreply.github.com>2022-03-31 11:27:43 +0200
committerthexai <58434170+thexai@users.noreply.github.com>2022-04-03 13:20:37 +0200
commit04dc89d26eb6e5e0a7256d6464098fc2667ea38c (patch)
tree6265871b15068bbf2dbe6729053954b2837a91bd
parent71fb3d3a63992c270b1cdac953020eb8848f6b1f (diff)
[Windows] Fix portable mode
Also removes global g_application from WIN32Util.cpp
-rw-r--r--xbmc/Application.h1
-rw-r--r--xbmc/platform/win32/WIN32Util.cpp5
-rw-r--r--xbmc/platform/win32/WIN32Util.h2
-rw-r--r--xbmc/platform/win32/WinMain.cpp47
-rw-r--r--xbmc/platform/win32/threads/Win32Exception.cpp7
-rw-r--r--xbmc/platform/win32/threads/Win32Exception.h2
-rw-r--r--xbmc/settings/SettingsComponent.cpp2
7 files changed, 34 insertions, 32 deletions
diff --git a/xbmc/Application.h b/xbmc/Application.h
index 0ea542ef83..5d96abe42d 100644
--- a/xbmc/Application.h
+++ b/xbmc/Application.h
@@ -268,7 +268,6 @@ public:
int GlobalIdleTime();
- bool PlatformDirectoriesEnabled() { return m_bPlatformDirectories; }
bool IsStandAlone() { return m_bStandalone; }
bool IsEnableTestMode() { return m_bTestMode; }
diff --git a/xbmc/platform/win32/WIN32Util.cpp b/xbmc/platform/win32/WIN32Util.cpp
index 177ab818dc..edd33134a2 100644
--- a/xbmc/platform/win32/WIN32Util.cpp
+++ b/xbmc/platform/win32/WIN32Util.cpp
@@ -8,7 +8,6 @@
#include "WIN32Util.h"
-#include "Application.h"
#include "CompileInfo.h"
#include "ServiceBroker.h"
#include "Util.h"
@@ -363,7 +362,7 @@ std::string CWIN32Util::GetSystemPath()
#endif
}
-std::string CWIN32Util::GetProfilePath()
+std::string CWIN32Util::GetProfilePath(const bool platformDirectories)
{
std::string strProfilePath;
#ifdef TARGET_WINDOWS_STORE
@@ -372,7 +371,7 @@ std::string CWIN32Util::GetProfilePath()
#else
std::string strHomePath = CUtil::GetHomePath();
- if(g_application.PlatformDirectoriesEnabled())
+ if (platformDirectories)
strProfilePath = URIUtils::AddFileToFolder(GetSpecialFolder(CSIDL_APPDATA|CSIDL_FLAG_CREATE), CCompileInfo::GetAppName());
else
strProfilePath = URIUtils::AddFileToFolder(strHomePath , "portable_data");
diff --git a/xbmc/platform/win32/WIN32Util.h b/xbmc/platform/win32/WIN32Util.h
index dcfcf26f17..7859c16231 100644
--- a/xbmc/platform/win32/WIN32Util.h
+++ b/xbmc/platform/win32/WIN32Util.h
@@ -44,7 +44,7 @@ public:
static size_t GetSystemMemorySize();
static std::string GetSystemPath();
- static std::string GetProfilePath();
+ static std::string GetProfilePath(const bool platformDirectories);
static std::string UncToSmb(const std::string &strPath);
static std::string SmbToUnc(const std::string &strPath);
static bool AddExtraLongPathPrefix(std::wstring& path);
diff --git a/xbmc/platform/win32/WinMain.cpp b/xbmc/platform/win32/WinMain.cpp
index 52b91d955a..40e5a386f9 100644
--- a/xbmc/platform/win32/WinMain.cpp
+++ b/xbmc/platform/win32/WinMain.cpp
@@ -38,7 +38,25 @@ LONG WINAPI CreateMiniDump(EXCEPTION_POINTERS* pEp)
//-----------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT)
{
- using KODI::PLATFORM::WINDOWS::ToW;
+ // parse command line parameters
+ int argc = 0;
+ LPWSTR* argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
+
+ char** argv = new char*[argc];
+
+ for (int i = 0; i < argc; ++i)
+ {
+ int size = WideCharToMultiByte(CP_UTF8, 0, argvW[i], -1, nullptr, 0, nullptr, nullptr);
+ if (size > 0)
+ {
+ argv[i] = new char[size];
+ WideCharToMultiByte(CP_UTF8, 0, argvW[i], -1, argv[i], size, nullptr, nullptr);
+ }
+ }
+
+ CAppParamParser appParamParser;
+ appParamParser.Parse(argv, argc);
+
// this fixes crash if OPENSSL_CONF is set to existed openssl.cfg
// need to set it as soon as possible
CEnvironment::unsetenv("OPENSSL_CONF");
@@ -55,10 +73,12 @@ INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT)
if (win32_exception::ShouldHook())
{
win32_exception::set_version(std::string(ver));
+ win32_exception::set_platformDirectories(appParamParser.HasPlatformDirectories());
SetUnhandledExceptionFilter(CreateMiniDump);
}
// check if Kodi is already running
+ using KODI::PLATFORM::WINDOWS::ToW;
std::string appName = CCompileInfo::GetAppName();
HANDLE appRunningMutex = CreateMutex(nullptr, FALSE, ToW(appName + " Media Center").c_str());
if (GetLastError() == ERROR_ALREADY_EXISTS)
@@ -78,22 +98,6 @@ INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT)
//Initialize COM
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
-
- int argc;
- LPWSTR* argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
-
- char** argv = new char*[argc];
-
- for (int i = 0; i < argc; ++i)
- {
- int size = WideCharToMultiByte(CP_UTF8, 0, argvW[i], -1, nullptr, 0, nullptr, nullptr);
- if (size > 0)
- {
- argv[i] = new char[size];
- int result = WideCharToMultiByte(CP_UTF8, 0, argvW[i], -1, argv[i], size, nullptr, nullptr);
- }
- }
-
// Initialise Winsock
WSADATA wd;
WSAStartup(MAKEWORD(2, 2), &wd);
@@ -106,13 +110,8 @@ INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT)
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
#endif
- int status;
- {
- CAppParamParser appParamParser;
- appParamParser.Parse(argv, argc);
- // Create and run the app
- status = XBMC_Run(true, appParamParser);
- }
+ // Create and run the app
+ int status = XBMC_Run(true, appParamParser);
for (int i = 0; i < argc; ++i)
delete[] argv[i];
diff --git a/xbmc/platform/win32/threads/Win32Exception.cpp b/xbmc/platform/win32/threads/Win32Exception.cpp
index 8590aeabe8..4768d34c39 100644
--- a/xbmc/platform/win32/threads/Win32Exception.cpp
+++ b/xbmc/platform/win32/threads/Win32Exception.cpp
@@ -58,6 +58,7 @@ typedef DWORD (__stdcall *tSSO)( IN DWORD SymOptions );
typedef LONG (__stdcall *GCPFN)(UINT32*, PWSTR);
std::string win32_exception::mVersion;
+bool win32_exception::m_platformDir;
bool win32_exception::write_minidump(EXCEPTION_POINTERS* pEp)
{
@@ -72,7 +73,8 @@ bool win32_exception::write_minidump(EXCEPTION_POINTERS* pEp)
mVersion, stLocalTime.year, stLocalTime.month, stLocalTime.day,
stLocalTime.hour, stLocalTime.minute, stLocalTime.second);
- dumpFileName = CWIN32Util::SmbToUnc(URIUtils::AddFileToFolder(CWIN32Util::GetProfilePath(), CUtil::MakeLegalFileName(dumpFileName)));
+ dumpFileName = CWIN32Util::SmbToUnc(URIUtils::AddFileToFolder(
+ CWIN32Util::GetProfilePath(m_platformDir), CUtil::MakeLegalFileName(dumpFileName)));
dumpFileNameW = KODI::PLATFORM::WINDOWS::ToW(dumpFileName);
HANDLE hDumpFile = CreateFileW(dumpFileNameW.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
@@ -187,7 +189,8 @@ bool win32_exception::write_stacktrace(EXCEPTION_POINTERS* pEp)
mVersion, stLocalTime.year, stLocalTime.month, stLocalTime.day,
stLocalTime.hour, stLocalTime.minute, stLocalTime.second);
- dumpFileName = CWIN32Util::SmbToUnc(URIUtils::AddFileToFolder(CWIN32Util::GetProfilePath(), CUtil::MakeLegalFileName(dumpFileName)));
+ dumpFileName = CWIN32Util::SmbToUnc(URIUtils::AddFileToFolder(
+ CWIN32Util::GetProfilePath(m_platformDir), CUtil::MakeLegalFileName(dumpFileName)));
dumpFileNameW = KODI::PLATFORM::WINDOWS::ToW(dumpFileName);
hDumpFile = CreateFileW(dumpFileNameW.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
diff --git a/xbmc/platform/win32/threads/Win32Exception.h b/xbmc/platform/win32/threads/Win32Exception.h
index b3419f0dc0..ae0c08eabf 100644
--- a/xbmc/platform/win32/threads/Win32Exception.h
+++ b/xbmc/platform/win32/threads/Win32Exception.h
@@ -16,9 +16,11 @@ public:
typedef const void* Address; // OK on Win32 platform
static void set_version(std::string version) { mVersion = version; }
+ static void set_platformDirectories(const bool platformDir) { m_platformDir = platformDir; }
static bool write_minidump(EXCEPTION_POINTERS* pEp);
static bool write_stacktrace(EXCEPTION_POINTERS* pEp);
static bool ShouldHook();
private:
static std::string mVersion;
+ static bool m_platformDir;
};
diff --git a/xbmc/settings/SettingsComponent.cpp b/xbmc/settings/SettingsComponent.cpp
index 90199cd712..7db974643f 100644
--- a/xbmc/settings/SettingsComponent.cpp
+++ b/xbmc/settings/SettingsComponent.cpp
@@ -350,7 +350,7 @@ bool CSettingsComponent::InitDirectoriesWin32(bool bPlatformDirectories)
CSpecialProtocol::SetXBMCPath(xbmcPath);
CSpecialProtocol::SetXBMCBinAddonPath(xbmcPath + "/addons");
- std::string strWin32UserFolder = CWIN32Util::GetProfilePath();
+ std::string strWin32UserFolder = CWIN32Util::GetProfilePath(bPlatformDirectories);
CSpecialProtocol::SetLogPath(strWin32UserFolder);
CSpecialProtocol::SetHomePath(strWin32UserFolder);
CSpecialProtocol::SetMasterProfilePath(URIUtils::AddFileToFolder(strWin32UserFolder, "userdata"));