Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
fesily committed Aug 22, 2024
1 parent 37873d4 commit 22ce1db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/DontStarveInjector/gameio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ static std::optional<std::filesystem::path> get_workshop_dir() {
if (cmd.contains(flag)) {
const auto cmds = get_cwds();
auto iter = std::find(cmds.begin(), cmds.end(), flag);
iter++;
const auto& value = *iter;
dir = value;
spdlog::info("workshop_dir ugc_directory: {}", value);
if (iter != cmds.end()) {
iter++;
if (iter != cmds.end()) {
const auto &value = *iter;
dir = value;
spdlog::info("workshop_dir ugc_directory: {}", value);
}
}
}
return dir / "content" / "322330";
}
Expand Down
22 changes: 13 additions & 9 deletions src/DontStarveInjector/loader/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const std::optional<luajit_config>& getLuajitConfig();

static std::optional<std::filesystem::path> getModDir() {
auto& config = getLuajitConfig();
if (config)
if (config && !config->modmain_path.empty())
return std::filesystem::path(config->modmain_path).parent_path();
return std::nullopt;
}
Expand Down Expand Up @@ -101,10 +101,7 @@ static auto need_updater() {
void updater();

static auto unsetup_pre(std::filesystem::path game_dir) {
// unsetup
SetEnvironmentVariableW(L"GAME_FILE", (game_dir / "Winmm.dll").c_str());

return "rm $Env:GAME_FILE";
return "rm Winmm.dll";
}

static std::optional<const char *> setup_pre(std::filesystem::path game_dir) {
Expand Down Expand Up @@ -143,27 +140,34 @@ static void installer(bool setup, bool restart) {
} else {
update_cmd = unsetup_pre(game_dir);
}

//powershell -NoExit -Command Wait-Process 13860; rm winmm.dll;start dontstarve_steam_x64.exe
#define DEBUG_SHELL !NDEBUG
auto cmd = std::format("powershell"
#if !NDEBUG
" -NoExit"
#endif
" -Command $Host.UI.RawUI.WindowTitle='LUAJIT_UPDATER';Wait-Process {}; {};"
" -Command Wait-Process {};sleep 3; {};"
#ifdef ENABLE_STEAM_SUPPORT
"start steam://rungameid/322330;"
#endif
,
GetCurrentProcessId(), update_cmd);
#ifndef ENABLE_STEAM_SUPPORT
cmd += "start " + getExePath().string();
cmd += std::format("start {}", getExePath().filename().string());
#endif
spdlog::info("run shell:{}", cmd);
if (CreateProcessA(NULL, cmd.data(), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if (!restart)
if (restart) {
if (!setup) {
auto p = getModinfoLuaPath();
if (p && std::filesystem::exists(p.value())) {
std::filesystem::remove(p.value());
}
}
std::exit(0);
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/DontStarveInjector/util/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,15 @@ std::string get_cwd(uintptr_t pid) {
std::vector<std::string> get_cwds(uintptr_t pid) {
std::vector<std::string> cmds;
#ifdef _WIN32
cmds.resize(__argc);
for (int i = 0; i < __argc; i++) {
cmds[i] = __argv[i];
auto cmd = get_cwd(pid);
int n = 0;
if (auto argv = CommandLineToArgvW(std::filesystem::path(cmd).wstring().c_str(), &n); argv) {
cmds.resize(n);
for (int i = 0; i < n; i++) {
cmds[i] = std::filesystem::path(argv[i]).string();
}
}
return cmds;
#else
auto param = pid == 0 ? std::string("/proc/self/cmdline") : "/proc/" + std::to_string(pid) + "/cmdline";
std::ifstream file(param.c_str());
Expand Down

0 comments on commit 22ce1db

Please sign in to comment.