Skip to content

Commit 8e9da8e

Browse files
committed
Fixed the portable version loading configuration file.
1 parent fff1db1 commit 8e9da8e

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

.vscode/settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"files.associations": {
3-
"*.manifest": "xml",
43
"*.env": "jsonc",
4+
"*.manifest": "xml",
55
"*.ipp": "cpp",
66
"vector": "cpp",
77
"xstring": "cpp",
@@ -84,6 +84,9 @@
8484
"span": "cpp",
8585
"stop_token": "cpp",
8686
"format": "cpp",
87-
"source_location": "cpp"
87+
"source_location": "cpp",
88+
"any": "cpp",
89+
"codecvt": "cpp",
90+
"ranges": "cpp"
8891
}
8992
}

AppExec/settings.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace priv {
1212
bool AppInitializeSettings(AppSettings &as) {
13-
auto file = PathSearcher::Instance().JoinAppData(L"Privexec\\AppExec.json");
13+
auto file = PathSearcher::Instance().JoinAppData(LR"(Privexec\AppExec.json)");
1414
FD fd;
1515
if (_wfopen_s(&fd.fd, file.data(), L"rb") != 0) {
1616
return false;
@@ -29,7 +29,7 @@ bool AppInitializeSettings(AppSettings &as) {
2929
}
3030

3131
bool AppApplySettings(const AppSettings &as) {
32-
auto file = PathSearcher::Instance().JoinAppData(L"Privexec\\AppExec.json");
32+
auto file = PathSearcher::Instance().JoinAppData(LR"(Privexec\AppExec.json)");
3333
std::filesystem::path p(file);
3434
auto parent = p.parent_path();
3535
std::error_code e;

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ endif()
7070

7171
#
7272
set(PRIVEXEC_VERSION_MAJOR 5)
73-
set(PRIVEXEC_VERSION_MINOR 0)
74-
set(PRIVEXEC_VERSION_PATCH 4)
73+
set(PRIVEXEC_VERSION_MINOR 1)
74+
set(PRIVEXEC_VERSION_PATCH 0)
7575
set(PACKAGE_VERSION "${PRIVEXEC_VERSION_MAJOR}.${PRIVEXEC_VERSION_MINOR}.${PRIVEXEC_VERSION_PATCH}")
7676

7777
string(TOLOWER "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" COMPILER_ARCH_ID)

Privexec/alias.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ struct alias_item_t {
1818
};
1919
bool AppAliasInitializeBuilt(std::wstring_view file) {
2020
constexpr alias_item_t items[] = {
21-
{"windbg", "Windows Debugger", "\"%ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x64\\windbg.exe\""}, //
22-
{"edit-hosts", "Edit Hosts", "Notepad %windir%\\System32\\Drivers\\etc\\hosts"}, //
21+
{"edit-hosts", "Edit Hosts", "Notepad %windir%\\System32\\Drivers\\etc\\hosts"}, //
2322
};
2423
try {
2524
nlohmann::json j;
@@ -33,6 +32,14 @@ bool AppAliasInitializeBuilt(std::wstring_view file) {
3332
}
3433
j["alias"] = alias;
3534
bela::error_code ec;
35+
std::filesystem::path p(file);
36+
auto parent = p.parent_path();
37+
if (std::error_code e; !std::filesystem::exists(parent, e)) {
38+
if (!std::filesystem::create_directories(parent, e)) {
39+
ec = bela::make_error_code_from_std(e);
40+
return false;
41+
}
42+
}
3643
if (!bela::io::AtomicWriteText(file, bela::io::as_bytes<char>(j.dump(4)), ec)) {
3744
return false;
3845
}
@@ -45,11 +52,11 @@ bool AppAliasInitializeBuilt(std::wstring_view file) {
4552

4653
std::wstring AppAliasFile() {
4754
//
48-
return PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
55+
return PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
4956
}
5057

5158
bool AppAliasInitialize(HWND hbox, priv::alias_t &alias) {
52-
auto file = PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
59+
auto file = PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
5360
if (!bela::PathExists(file)) {
5461
if (!AppAliasInitializeBuilt(file)) {
5562
return false;

Privexec/app.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool App::Initialize(HWND window) {
6868
box.Append((int)wsudo::exec::privilege_t::elevated, L"Administrator", true);
6969
}
7070
HMENU hSystemMenu = ::GetSystemMenu(hWnd, FALSE);
71-
InsertMenuW(hSystemMenu, SC_CLOSE, MF_ENABLED, IDM_EDIT_ALIASFILE, L"Open Privexec.json");
71+
InsertMenuW(hSystemMenu, SC_CLOSE, MF_ENABLED, IDM_EDIT_ALIASFILE, L"Edit Privexec.json");
7272
InsertMenuW(hSystemMenu, SC_CLOSE, MF_ENABLED, IDM_PRIVEXEC_ABOUT, L"About Privexec\tAlt+F1");
7373
cmd.hInput = GetDlgItem(hWnd, IDC_COMMAND_COMBOX);
7474
cmd.hButton = GetDlgItem(hWnd, IDB_COMMAND_TARGET);

include/vfsenv.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ class PathSearcher {
4343
PathSearcher() {
4444
bela::error_code ec;
4545
if (!vfsInitialize(ec)) {
46-
etc = std::filesystem::path{L"."};
46+
if (auto e = bela::ExecutableFinalPathParent(ec); e) {
47+
basePath = std::filesystem::path{*e};
48+
appdata = basePath / L"appdata";
49+
etc = basePath / L"etc";
50+
return;
51+
}
4752
basePath = std::filesystem::path{L"."};
48-
appdata = std::filesystem::path{L"."};
53+
appdata = basePath / L"appdata";
54+
etc = basePath / L"etc";
4955
}
5056
}
5157

wsudo/alias.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ wsudo::AliasEngine::~AliasEngine() {
1818
}
1919

2020
bool wsudo::AliasEngine::Initialize(bool verbose) {
21-
auto file = priv::PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
21+
auto file = priv::PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
2222
DbgPrint(L"use %s", file);
2323
priv::FD fd;
2424
if (auto en = _wfopen_s(&fd.fd, file.data(), L"rb"); en != 0) {
@@ -49,7 +49,7 @@ std::optional<std::wstring> wsudo::AliasEngine::Target(std::wstring_view al) {
4949
}
5050

5151
bool wsudo::AliasEngine::Apply() {
52-
auto file = priv::PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
52+
auto file = priv::PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
5353
DbgPrint(L"use %s", file);
5454
std::filesystem::path p(file);
5555
auto parent = p.parent_path();

0 commit comments

Comments
 (0)