From b6618b42a2a87ce621c2f3b8b8208fd8cc1cffd6 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 15 Oct 2019 09:24:09 -0400 Subject: [PATCH] Provide a cleaner error message for windows.wt If Windows.wt is missing, surge can go horribly awry. We issued no error message in this case. So do so now. Closes #1247 --- src/common/SurgeStorage.cpp | 28 ++++++++++++++++++++++++---- src/common/SurgeStorage.h | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index a736382ba0b..c19f33108f3 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -303,7 +303,24 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) // WindowWT is a WaveTable which now has a constructor so don't do this // memset(&WindowWT, 0, sizeof(WindowWT)); - load_wt_wt(datapath + "windows.wt", &WindowWT); + if( ! load_wt_wt(datapath + "windows.wt", &WindowWT) ) + { + std::ostringstream oss; + oss << "Unable to load '" << datapath << "/windows.wt'. This file is required for surge to operate " + << "properly. This occurs when Surge is mis-installed and shared resources are not in the " + << "os-specific shared directory, which on your OS is a directory called 'Surge' in " +#if MAC + << "the global or user local `Library/Application Support` directory." +#endif +#if WINDOWS + << "your %LocalAppData% directory." +#endif +#if LINUX + << "/usr/share or ~/.local/share." +#endif + << " Please install shared assets correctly and restart."; + Surge::UserInteractions::promptError(oss.str(), "Unable to load windows.wt"); + } } SurgePatch& SurgeStorage::getPatch() @@ -703,11 +720,11 @@ void SurgeStorage::load_wt(string filename, Wavetable* wt) } } -void SurgeStorage::load_wt_wt(string filename, Wavetable* wt) +bool SurgeStorage::load_wt_wt(string filename, Wavetable* wt) { FILE* f = fopen(filename.c_str(), "rb"); if (!f) - return; + return false; wt_header wh; memset(&wh, 0, sizeof(wt_header)); @@ -718,7 +735,7 @@ void SurgeStorage::load_wt_wt(string filename, Wavetable* wt) { // SOME sort of error reporting is appropriate fclose(f); - return; + return false; } void* data; @@ -747,8 +764,11 @@ void SurgeStorage::load_wt_wt(string filename, Wavetable* wt) << " https://github.com/surge-synthesizer/surge/"; Surge::UserInteractions::promptError( oss.str(), "Software Error on WT Load" ); + fclose(f); + return false; } fclose(f); + return true; } int SurgeStorage::get_clipboard_type() { diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 6454c25abe7..e12406d2695 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -550,7 +550,7 @@ class alignas(16) SurgeStorage void load_wt(int id, Wavetable* wt); void load_wt(std::string filename, Wavetable* wt); - void load_wt_wt(std::string filename, Wavetable* wt); + bool load_wt_wt(std::string filename, Wavetable* wt); // void load_wt_wav(std::string filename, Wavetable* wt); void load_wt_wav_portable(std::string filename, Wavetable *wt); void clipboard_copy(int type, int scene, int entry);