Skip to content

Commit

Permalink
Merge pull request #5 from x1nixmzeng/launch-mount-path
Browse files Browse the repository at this point in the history
Add flag to launch mounted folder in Explorer
  • Loading branch information
x1nixmzeng authored Jan 4, 2021
2 parents 2157eaf + 6281fec commit 70adb6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Once mounted, the files can be

xbox-iso-vfs.exe [/d|/l] <iso_file> <mount_path>
/d Display debug Dokan output in console window
/l Open Windows Explorer to the mount path
<iso_file> Path to the Xbox ISO file to mount
<mount_path> Driver letter ("M:\") or folder path on NTFS partition
/h Show usage
Expand Down
36 changes: 28 additions & 8 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "vfs.h"
#include "vfs_operations.h"

#include <chrono>
#include <cstdio>
#include <filesystem>
#include <iostream>
#include <string>
#include <thread>

template <class T> class Singleton {
public:
Expand All @@ -33,7 +35,7 @@ class App : public Singleton<App> {
std::wstring filePath;
std::wstring mountPoint;
bool debugMode{false};
// bool launchMountPath{ true };
bool launchMountPath{false};
};

App(const Parameters &params) : m_params(params) {}
Expand All @@ -57,6 +59,16 @@ class App : public Singleton<App> {
}
}

static void fileWatcher(std::wstring path) {
std::filesystem::path mp(path);

do {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
} while (std::filesystem::exists(mp) == false);

ShellExecuteW(0, L"explore", path.c_str(), NULL, NULL, SW_SHOWNORMAL);
}

void runDokan() {
DOKAN_OPTIONS dokanOptions;
ZeroMemory(&dokanOptions, sizeof(DOKAN_OPTIONS));
Expand All @@ -82,6 +94,11 @@ class App : public Singleton<App> {

vfs::setup(dokanOperations);

std::thread watcher;
if (m_params.launchMountPath) {
watcher = std::thread(fileWatcher, m_params.mountPoint);
}

auto status = DokanMain(&dokanOptions, &dokanOperations);

// Solutions are suggested where possible
Expand Down Expand Up @@ -125,16 +142,20 @@ class App : public Singleton<App> {
std::wcout << "Please create an issue on Github with this number\n";
break;
}

if (watcher.joinable()) {
watcher.detach();
}
}

static void showUsage() {
std::wcout
<< "xbox-iso-vfs is a utility to mount Xbox ISO files on Windows\n";
std::wcout << "Written by x1nixmzeng\n\n";
std::wcout << "xbox-iso-vfs.exe [/d] <iso_file> <mount_path>\n";
std::wcout << "xbox-iso-vfs.exe [/d|/l] <iso_file> <mount_path>\n";
std::wcout
<< " /d Display debug Dokan output in console window\n";
// std::wcout << " /l Launch the mount path when successful\n";
std::wcout << " /l Open Windows Explorer to the mount path\n";
std::wcout << " <iso_file> Path to the Xbox ISO file to mount\n";
std::wcout << " <mount_path> Driver letter (\"M:\\\") or folder path on "
"NTFS partition\n";
Expand All @@ -154,11 +175,10 @@ class App : public Singleton<App> {
} else if (arg == L"--debug" || arg == L"/d") {
params.debugMode = true;
continue;
}
// else if (arg == L"--launch" || arg == L"/l") {
// params.launchMountPath = true;
//}
else if (i + 1 >= argc) {
} else if (arg == L"--launch" || arg == L"/l") {
params.launchMountPath = true;
continue;
} else if (i + 1 >= argc) {
std::wcout << "Missing mount_path parameter. Use --help to see usage\n";
return false;
}
Expand Down

0 comments on commit 70adb6f

Please sign in to comment.