Browse Source

Open patch with command-line argument, set Windows global directory to

location of executable instead of current working directory.
tags/v0.6.1
Andrew Belt 6 years ago
parent
commit
d3fa318d32
3 changed files with 35 additions and 22 deletions
  1. +1
    -1
      Makefile
  2. +6
    -2
      src/asset.cpp
  3. +28
    -19
      src/main.cpp

+ 1
- 1
Makefile View File

@@ -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


+ 6
- 2
src/asset.cpp View File

@@ -11,6 +11,7 @@
#if ARCH_WIN
#include <Windows.h>
#include <Shlobj.h>
#include <Shlwapi.h>
#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


+ 28
- 19
src/main.cpp View File

@@ -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();


Loading…
Cancel
Save