diff --git a/Makefile b/Makefile index 272073a4..3683a2ca 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ ifeq ($(ARCH), win) LDFLAGS += -static \ -Wl,--export-all-symbols,--out-implib,libRack.a -mwindows \ -Ldep/lib -lglew32 -lglfw3 -ljansson -lspeexdsp -lzip -lz -lcurl -lssl -lcrypto -lrtaudio -lrtmidi \ - -lpthread -lopengl32 -lgdi32 -lws2_32 -lcomdlg32 -lole32 -ldsound -lwinmm -lksuser + -lpthread -lopengl32 -lgdi32 -lws2_32 -lcomdlg32 -lole32 -ldsound -lwinmm -lksuser -lshlwapi TARGET := Rack.exe OBJECTS += Rack.res endif diff --git a/src/asset.cpp b/src/asset.cpp index 13ee0e7e..04f46a58 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -11,6 +11,7 @@ #if ARCH_WIN #include #include +#include #endif #if ARCH_LIN @@ -37,8 +38,11 @@ std::string assetGlobal(std::string filename) { dir = buf; #endif #if ARCH_WIN - // Must launch Rack with the "Start In" directory as the global directory - dir = "."; + char buf[MAX_PATH]; + DWORD length = GetModuleFileName(NULL, buf, sizeof(buf)); + assert(length > 0); + PathRemoveFileSpec(buf); + dir = buf; #endif #if ARCH_LIN // TODO For now, users should launch Rack from their terminal in the global directory diff --git a/src/main.cpp b/src/main.cpp index 5d5aa2d4..cd506769 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,18 +19,19 @@ int main(int argc, char* argv[]) { randomInit(); loggerInit(); + // Parse command line arguments + std::string patchFile; + if (argc >= 2) { + patchFile = argv[1]; + } + info("Rack %s", gApplicationVersion.c_str()); - { - char *cwd = getcwd(NULL, 0); - info("Current working directory: %s", cwd); - free(cwd); - std::string globalDir = assetGlobal(""); - std::string localDir = assetLocal(""); - info("Global directory: %s", globalDir.c_str()); - info("Local directory: %s", localDir.c_str()); - } + // Log directories + info("Global directory: %s", assetGlobal("").c_str()); + info("Local directory: %s", assetLocal("").c_str()); + // Initialize namespaces pluginInit(); engineInit(); midiInit(); @@ -38,25 +39,33 @@ int main(int argc, char* argv[]) { windowInit(); appInit(); settingsLoad(assetLocal("settings.json")); - std::string oldLastPath = gRackWidget->lastPath; - // To prevent launch crashes, if Rack crashes between now and 15 seconds from now, the "skipAutosaveOnLaunch" property will remain in settings.json, so that in the next launch, the broken autosave will not be loaded. - bool oldSkipAutosaveOnLaunch = skipAutosaveOnLaunch; - skipAutosaveOnLaunch = true; - settingsSave(assetLocal("settings.json")); - skipAutosaveOnLaunch = false; - if (oldSkipAutosaveOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Would you like to clear your patch and start over?")) { - // Do nothing. Empty patch is already loaded. + if (patchFile.empty()) { + std::string oldLastPath = gRackWidget->lastPath; + // To prevent launch crashes, if Rack crashes between now and 15 seconds from now, the "skipAutosaveOnLaunch" property will remain in settings.json, so that in the next launch, the broken autosave will not be loaded. + bool oldSkipAutosaveOnLaunch = skipAutosaveOnLaunch; + skipAutosaveOnLaunch = true; + settingsSave(assetLocal("settings.json")); + skipAutosaveOnLaunch = false; + if (oldSkipAutosaveOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Would you like to clear your patch and start over?")) { + // Do nothing. Empty patch is already loaded. + } + else { + // Load autosave + gRackWidget->loadPatch(assetLocal("autosave.vcv")); + } + gRackWidget->lastPath = oldLastPath; } else { - gRackWidget->loadPatch(assetLocal("autosave.vcv")); + // Load patch + gRackWidget->loadPatch(patchFile); } - gRackWidget->lastPath = oldLastPath; engineStart(); windowRun(); engineStop(); + // Destroy namespaces gRackWidget->savePatch(assetLocal("autosave.vcv")); settingsSave(assetLocal("settings.json")); appDestroy();