mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
162 lines
5.8 KiB
C++
162 lines
5.8 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
|
Copyright 2004-10 by Raw Material Software Ltd.
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
JUCE can be redistributed and/or modified under the terms of the GNU General
|
|
Public License (Version 2), as published by the Free Software Foundation.
|
|
A copy of the license is included in the JUCE distribution, or can be found
|
|
online at www.gnu.org/licenses.
|
|
|
|
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
To release a closed-source product which uses JUCE, commercial licenses are
|
|
available: visit www.rawmaterialsoftware.com/juce for more information.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#include "../core/juce_StandardHeader.h"
|
|
|
|
BEGIN_JUCE_NAMESPACE
|
|
|
|
#include "juce_ApplicationProperties.h"
|
|
#include "../gui/components/windows/juce_AlertWindow.h"
|
|
#include "../text/juce_LocalisedStrings.h"
|
|
|
|
|
|
//==============================================================================
|
|
juce_ImplementSingleton (ApplicationProperties)
|
|
|
|
|
|
//==============================================================================
|
|
ApplicationProperties::ApplicationProperties()
|
|
: msBeforeSaving (3000),
|
|
options (PropertiesFile::storeAsBinary),
|
|
commonSettingsAreReadOnly (0),
|
|
processLock (0)
|
|
{
|
|
}
|
|
|
|
ApplicationProperties::~ApplicationProperties()
|
|
{
|
|
closeFiles();
|
|
clearSingletonInstance();
|
|
}
|
|
|
|
//==============================================================================
|
|
void ApplicationProperties::setStorageParameters (const String& applicationName,
|
|
const String& fileNameSuffix,
|
|
const String& folderName_,
|
|
const int millisecondsBeforeSaving,
|
|
const int propertiesFileOptions,
|
|
InterProcessLock* processLock_)
|
|
{
|
|
appName = applicationName;
|
|
fileSuffix = fileNameSuffix;
|
|
folderName = folderName_;
|
|
msBeforeSaving = millisecondsBeforeSaving;
|
|
options = propertiesFileOptions;
|
|
processLock = processLock_;
|
|
}
|
|
|
|
bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
|
|
const bool testCommonSettings,
|
|
const bool showWarningDialogOnFailure)
|
|
{
|
|
const bool userOk = (! testUserSettings) || getUserSettings()->save();
|
|
const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
|
|
|
|
if (! (userOk && commonOk))
|
|
{
|
|
if (showWarningDialogOnFailure)
|
|
{
|
|
String filenames;
|
|
|
|
if (userProps != 0 && ! userOk)
|
|
filenames << '\n' << userProps->getFile().getFullPathName();
|
|
|
|
if (commonProps != 0 && ! commonOk)
|
|
filenames << '\n' << commonProps->getFile().getFullPathName();
|
|
|
|
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
|
|
appName + TRANS(" - Unable to save settings"),
|
|
TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
|
|
+ appName + TRANS(" needs to be able to write to the following files:\n")
|
|
+ filenames
|
|
+ TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//==============================================================================
|
|
void ApplicationProperties::openFiles()
|
|
{
|
|
// You need to call setStorageParameters() before trying to get hold of the
|
|
// properties!
|
|
jassert (appName.isNotEmpty());
|
|
|
|
if (appName.isNotEmpty())
|
|
{
|
|
if (userProps == 0)
|
|
userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
|
|
false, msBeforeSaving, options, processLock);
|
|
|
|
if (commonProps == 0)
|
|
commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
|
|
true, msBeforeSaving, options, processLock);
|
|
|
|
userProps->setFallbackPropertySet (commonProps);
|
|
}
|
|
}
|
|
|
|
PropertiesFile* ApplicationProperties::getUserSettings()
|
|
{
|
|
if (userProps == 0)
|
|
openFiles();
|
|
|
|
return userProps;
|
|
}
|
|
|
|
PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly)
|
|
{
|
|
if (commonProps == 0)
|
|
openFiles();
|
|
|
|
if (returnUserPropsIfReadOnly)
|
|
{
|
|
if (commonSettingsAreReadOnly == 0)
|
|
commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
|
|
|
|
if (commonSettingsAreReadOnly > 0)
|
|
return userProps;
|
|
}
|
|
|
|
return commonProps;
|
|
}
|
|
|
|
bool ApplicationProperties::saveIfNeeded()
|
|
{
|
|
return (userProps == 0 || userProps->saveIfNeeded())
|
|
&& (commonProps == 0 || commonProps->saveIfNeeded());
|
|
}
|
|
|
|
void ApplicationProperties::closeFiles()
|
|
{
|
|
userProps = 0;
|
|
commonProps = 0;
|
|
}
|
|
|
|
|
|
END_JUCE_NAMESPACE
|