mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
-Writes default preferences file if it doesn't exist
This commit is contained in:
parent
6bfd6a86e1
commit
b186de0226
3 changed files with 49 additions and 2 deletions
|
@ -71,13 +71,15 @@ int DiskReader::loadPreferences()
|
|||
}
|
||||
|
||||
|
||||
cJSON* resample = cJSON_GetObjectItem( preferencesJson, "defaultControllers" );
|
||||
cJSON* resample = cJSON_GetObjectItem( preferencesJson, "resampleQuality" );
|
||||
if ( resample )
|
||||
{
|
||||
resampleQuality = resample->valueint;
|
||||
if ( resampleQuality == 0 )
|
||||
{
|
||||
LUPPP_NOTE("Using Linear resampling, may reduce quality. Check .config/openAV/luppp/luppp.prfs");
|
||||
}
|
||||
}
|
||||
cJSON* ctlrs = cJSON_GetObjectItem( preferencesJson, "defaultControllers" );
|
||||
if ( ctlrs )
|
||||
{
|
||||
|
@ -110,7 +112,11 @@ int DiskReader::loadPreferences()
|
|||
{
|
||||
// empty file / file no exists:
|
||||
LUPPP_WARN("Preferences, file doesn't exist: ~/.config/openAV/luppp/luppp.prefs");
|
||||
return LUPPP_RETURN_ERROR;
|
||||
|
||||
// so write default file
|
||||
gui->getDiskWriter()->writeDefaultConfigToUserHome();
|
||||
|
||||
return LUPPP_RETURN_OK;
|
||||
}
|
||||
|
||||
return LUPPP_RETURN_OK;
|
||||
|
|
|
@ -487,3 +487,42 @@ int DiskWriter::writeSession()
|
|||
|
||||
return LUPPP_RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
void DiskWriter::writeDefaultConfigToUserHome()
|
||||
{
|
||||
LUPPP_NOTE("Writing default preferences file.");
|
||||
|
||||
cJSON* prfs = cJSON_CreateObject();
|
||||
|
||||
// "__COMMENT__" : "users home + <whatever it says here>"
|
||||
// "saveDirectory" : "luppp"
|
||||
cJSON_AddItemToObject ( prfs, "__COMMENT__",
|
||||
cJSON_CreateString("users home + <whatever it says here>") );
|
||||
cJSON_AddItemToObject ( prfs, "saveDirectory", cJSON_CreateString( "luppp" ));
|
||||
|
||||
|
||||
// "__COMMENT__" : "0 = LINEAR, 1 = SINC_FASTEST, 2 = SINC_BEST",
|
||||
// "resampleQuality" : 2
|
||||
cJSON_AddItemToObject ( prfs, "__COMMENT__",
|
||||
cJSON_CreateString("0 = LINEAR, 1 = SINC_FASTEST, 2 = SINC_BEST") );
|
||||
cJSON_AddNumberToObject( prfs, "resampleQuality", 1 );
|
||||
|
||||
// "defaultControllers" : [],
|
||||
cJSON* defCtrls = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject( prfs, "defaultControllers", defCtrls );
|
||||
|
||||
|
||||
// test output on console
|
||||
// cout << endl << cJSON_Print( prfs ) << endl << endl;
|
||||
|
||||
|
||||
// write JSON to .config/openAV/luppp/luppp.prfs
|
||||
stringstream f;
|
||||
f << getenv("HOME") << "/.config/openAV/luppp/luppp.prfs";
|
||||
|
||||
ofstream outFile;
|
||||
outFile.open ( f.str().c_str() );
|
||||
outFile << cJSON_Print( prfs );
|
||||
outFile.close();
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ class DiskWriter
|
|||
/// writes a controller definition .ctlr JSON file from a GenericMIDI instance
|
||||
int writeControllerFile( Controller* c );
|
||||
|
||||
/// writes default config file to users home if it doesn't exist
|
||||
void writeDefaultConfigToUserHome();
|
||||
|
||||
#ifdef BUILD_TESTS
|
||||
int runTests();
|
||||
|
|
Loading…
Add table
Reference in a new issue