OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
installdetect.cpp
Go to the documentation of this file.
1#include "installdetect.h"
2
3#include <Tempest/Platform>
4
5#ifdef __WINDOWS__
6#include "windows.h"
7#include "shlobj.h"
8#include "shlwapi.h"
9#endif
10
11#include <cstring>
12#include "utils/fileutil.h"
13
15#ifdef __WINDOWS__
16 pfiles = programFiles(false);
17 pfilesX86 = programFiles(true);
18#endif
19#if defined(__OSX__) || defined(__IOS__)
20 appDir = applicationSupportDirectory();
21#endif
22 }
23
24std::u16string InstallDetect::detectG2() {
25#if defined(__WINDOWS__)
26 auto ret = detectG2(pfiles);
27 if(ret.empty())
28 ret = detectG2(pfilesX86);
29 return ret;
30#elif defined(__OSX__) || defined(__IOS__)
31 if(FileUtil::exists(appDir))
32 return appDir;
33 return u"";
34#else
35 return u"";
36#endif
37 }
38
39std::u16string InstallDetect::detectG2(std::u16string pfiles) {
40 if(pfiles.empty())
41 return u"";
42 auto steam = pfiles+u"/Steam/steamapps/common/Gothic II/";
43 if(FileUtil::exists(steam))
44 return steam;
45 auto akela = pfiles+u"/Akella Games/Gothic II/";
46 if(FileUtil::exists(akela))
47 return akela;
48 return u"";
49 }
50
51#ifdef __WINDOWS__
52std::u16string InstallDetect::programFiles(bool x86) {
53 WCHAR path[MAX_PATH]={};
54 if(FAILED(SHGetFolderPathW(NULL, (x86 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES), NULL, 0, path)))
55 return u"";
56 std::u16string ret;
57 size_t len=0;
58 for(;path[len];++len);
59
60 ret.resize(len);
61 std::memcpy(&ret[0],path,len*sizeof(char16_t));
62 return ret;
63 }
64#endif
std::u16string detectG2()
bool exists(const std::u16string &path)
Definition fileutil.cpp:15