Skip to content

Commit e082e59

Browse files
committed
Load config from correct location with static build
IB-8961 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent a820733 commit e082e59

3 files changed

Lines changed: 18 additions & 28 deletions

File tree

‎src/CMakeLists.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ add_library(digidocpp_tsl STATIC
8484
XMLDocument.h
8585
)
8686

87-
set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES
88-
POSITION_INDEPENDENT_CODE YES
89-
)
9087
target_compile_definitions(digidocpp_tsl PRIVATE $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,digidocpp_EXPORTS,digidocpp_STATIC>)
9188
target_compile_definitions(digidocpp_util PRIVATE $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,digidocpp_EXPORTS,digidocpp_STATIC>)
89+
set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES POSITION_INDEPENDENT_CODE YES)
9290

9391
target_include_directories(digidocpp_tsl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
9492

‎src/util/File.cpp‎

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "File.h"
2121

22+
#include "Container.h"
2223
#include "log.h"
2324

2425
#include <algorithm>
@@ -54,30 +55,38 @@ namespace fs = filesystem;
5455
#define f_stat _wstat64
5556
#define f_utime _wutime64
5657
using f_statbuf = struct _stat64;
57-
using f_utimbuf = struct __utimbuf64;
5858
#else
5959
#define f_stat stat
6060
#define f_utime utime
6161
using f_statbuf = struct stat;
62-
using f_utimbuf = struct utimbuf;
6362
#endif
6463

6564
stack<fs::path> File::tempFiles;
6665

67-
static string decodeName(fs::path path)
66+
static string decodeName(const fs::path &path)
6867
{
6968
auto name = path.u8string();
7069
return {reinterpret_cast<const char*>(name.data()), name.size()};
7170
}
7271

7372
string File::confPath()
7473
{
75-
#if defined(__APPLE__)
74+
#ifdef __APPLE__
7675
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 {};
8190
#else
8291
fs::path result;
8392
if(char *var = getenv("SNAP"))
@@ -107,20 +116,6 @@ bool File::fileExists(const string& path)
107116
return fs::is_regular_file(encodeName(path));
108117
}
109118

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-
124119
/**
125120
* Returns last modified time
126121
*

‎src/util/File.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ namespace digidoc
5353
static std::vector<unsigned char> hexToBin(std::string_view in);
5454

5555
private:
56-
#ifdef _WIN32
57-
static std::string dllPath(std::string_view dll);
58-
#endif
5956
#ifdef __APPLE__
6057
static std::string frameworkResourcesPath(std::string_view name);
6158
#endif

0 commit comments

Comments
 (0)