|
19 | 19 |
|
20 | 20 | #include "File.h" |
21 | 21 |
|
| 22 | +#include "Container.h" |
22 | 23 | #include "log.h" |
23 | 24 |
|
24 | 25 | #include <algorithm> |
@@ -54,30 +55,38 @@ namespace fs = filesystem; |
54 | 55 | #define f_stat _wstat64 |
55 | 56 | #define f_utime _wutime64 |
56 | 57 | using f_statbuf = struct _stat64; |
57 | | -using f_utimbuf = struct __utimbuf64; |
58 | 58 | #else |
59 | 59 | #define f_stat stat |
60 | 60 | #define f_utime utime |
61 | 61 | using f_statbuf = struct stat; |
62 | | -using f_utimbuf = struct utimbuf; |
63 | 62 | #endif |
64 | 63 |
|
65 | 64 | stack<fs::path> File::tempFiles; |
66 | 65 |
|
67 | | -static string decodeName(fs::path path) |
| 66 | +static string decodeName(const fs::path &path) |
68 | 67 | { |
69 | 68 | auto name = path.u8string(); |
70 | 69 | return {reinterpret_cast<const char*>(name.data()), name.size()}; |
71 | 70 | } |
72 | 71 |
|
73 | 72 | string File::confPath() |
74 | 73 | { |
75 | | -#if defined(__APPLE__) |
| 74 | +#ifdef __APPLE__ |
76 | 75 | return frameworkResourcesPath("ee.ria.digidocpp"); |
77 | | -#elif defined(_WIN32) && defined(_DEBUG) |
78 | | - return dllPath("digidocppd.dll"); |
79 | | -#elif defined(_WIN32) |
80 | | - return dllPath("digidocpp.dll"); |
| 76 | +#elifdef _WIN32 |
| 77 | + if(HMODULE handle {}; |
| 78 | + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
| 79 | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, |
| 80 | + reinterpret_cast<LPCWSTR>(&digidoc::terminate), |
| 81 | + &handle)) |
| 82 | + { |
| 83 | + wstring path(MAX_PATH, 0); |
| 84 | + path.resize(GetModuleFileNameW(handle, path.data(), DWORD(path.size()))); |
| 85 | + if(size_t pos = path.find_last_of(L"/\\"); pos != wstring::npos) |
| 86 | + path.resize(pos); |
| 87 | + return decodeName(std::move(path)); |
| 88 | + } |
| 89 | + return {}; |
81 | 90 | #else |
82 | 91 | fs::path result; |
83 | 92 | if(char *var = getenv("SNAP")) |
@@ -107,20 +116,6 @@ bool File::fileExists(const string& path) |
107 | 116 | return fs::is_regular_file(encodeName(path)); |
108 | 117 | } |
109 | 118 |
|
110 | | -#ifdef _WIN32 |
111 | | -string File::dllPath(string_view dll) |
112 | | -{ |
113 | | -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) |
114 | | - HMODULE handle = GetModuleHandleW(encodeName(dll).c_str()); |
115 | | - wstring path(MAX_PATH, 0); |
116 | | - path.resize(GetModuleFileNameW(handle, path.data(), DWORD(path.size()))); |
117 | | - return decodeName(fs::path(path).parent_path()); |
118 | | -#else |
119 | | - return {}; |
120 | | -#endif |
121 | | -} |
122 | | -#endif |
123 | | - |
124 | 119 | /** |
125 | 120 | * Returns last modified time |
126 | 121 | * |
|
0 commit comments