diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/globalFunctions.h | 20 | ||||
-rw-r--r-- | library/pch.h | 3 | ||||
-rw-r--r-- | library/processXml.cpp | 484 | ||||
-rw-r--r-- | library/processXml.h | 114 | ||||
-rw-r--r-- | library/resources.cpp | 241 | ||||
-rw-r--r-- | library/resources.h | 136 |
6 files changed, 767 insertions, 231 deletions
diff --git a/library/globalFunctions.h b/library/globalFunctions.h index 7f50f90a..40eba94f 100644 --- a/library/globalFunctions.h +++ b/library/globalFunctions.h @@ -19,19 +19,19 @@ namespace globalFunctions return(d<0?-d:d); } - string numberToString(const unsigned int number); //Convert number to string - string numberToString(const int number); //Convert number to string - string numberToString(const float number); //Convert number to string + string numberToString(const unsigned int number); //convert number to string + string numberToString(const int number); //convert number to string + string numberToString(const float number); //convert number to string - wxString numberToWxString(const unsigned int number); //Convert number to wxString - wxString numberToWxString(const int number); //Convert number to wxString - wxString numberToWxString(const float number); //Convert number to wxString + wxString numberToWxString(const unsigned int number); //convert number to wxString + wxString numberToWxString(const int number); //convert number to wxString + wxString numberToWxString(const float number); //convert number to wxString - int stringToInt( const string& number); //Convert String to number - double stringToDouble(const string& number); //Convert String to number + int stringToInt( const string& number); //convert String to number + double stringToDouble(const string& number); //convert String to number - int wxStringToInt( const wxString& number); //Convert wxString to number - double wxStringToDouble(const wxString& number); //Convert wxString to number + int wxStringToInt( const wxString& number); //convert wxString to number + double wxStringToDouble(const wxString& number); //convert wxString to number wxString& includeNumberSeparator(wxString& number); diff --git a/library/pch.h b/library/pch.h index 37c3383f..50f9fda3 100644 --- a/library/pch.h +++ b/library/pch.h @@ -1,7 +1,8 @@ #ifndef FFS_PRECOMPILED_HEADER #define FFS_PRECOMPILED_HEADER -DO NOT USE THIS FILE: FOR SOME REASON IT CORRUPTS COMPILATION!!! +DO NOT USE THIS FILE: +FOR SOME REASON IT CORRUPTS COMPILATION!!! //##################################################### // basic wxWidgets headers diff --git a/library/processXml.cpp b/library/processXml.cpp new file mode 100644 index 00000000..80f284c2 --- /dev/null +++ b/library/processXml.cpp @@ -0,0 +1,484 @@ +#include "processXml.h" +#include <wx/filefn.h> +#include <wx/ffile.h> +#include "globalFunctions.h" + +using namespace globalFunctions; +using namespace xmlAccess; + + +XmlType xmlAccess::getXmlType(const wxString& filename) +{ + if (!wxFileExists(filename)) + return XML_OTHER; + + //workaround to get a FILE* from a unicode filename + wxFFile configFile(filename, wxT("rb")); + if (!configFile.IsOpened()) + return XML_OTHER; + + FILE* inputFile = configFile.fp(); + + TiXmlDocument doc; + if (!doc.LoadFile(inputFile)) //fails if inputFile is no proper XML + return XML_OTHER; + + TiXmlElement* root = doc.RootElement(); + + if (!root || (root->ValueStr() != string("FreeFileSync"))) //check for FFS configuration xml + return XML_OTHER; + + const char* cfgType = root->Attribute("XmlType"); + if (!cfgType) + return XML_OTHER; + + if (string(cfgType) == "BATCH") + return XML_BATCH_CONFIG; + else if (string(cfgType) == "GUI") + return XML_GUI_CONFIG; + else + return XML_OTHER; +} + + +XmlInput::XmlInput(const wxString& fileName, const XmlType type) : + loadSuccess(false) +{ + if (!wxFileExists(fileName)) //avoid wxWidgets error message when wxFFile receives not existing file + return; + + //workaround to get a FILE* from a unicode filename + wxFFile dummyFile(fileName, wxT("rb")); + if (dummyFile.IsOpened()) + { + FILE* inputFile = dummyFile.fp(); + + TiXmlBase::SetCondenseWhiteSpace(false); //do not condense whitespace characters + + if (doc.LoadFile(inputFile)) //load XML; fails if inputFile is no proper XML + { + TiXmlElement* root = doc.RootElement(); + + if (root && (root->ValueStr() == string("FreeFileSync"))) //check for FFS configuration xml + { + const char* cfgType = root->Attribute("XmlType"); + if (cfgType) + { + if (type == XML_GUI_CONFIG) + loadSuccess = string(cfgType) == "GUI"; + else if (type == XML_BATCH_CONFIG) + loadSuccess = string(cfgType) == "BATCH"; + } + } + } + } +} + + +bool XmlInput::readXmlElementValue(string& output, const TiXmlElement* parent, const string& name) +{ + if (parent) + { + const TiXmlElement* child = parent->FirstChildElement(name); + if (child) + { + const char* text = child->GetText(); + if (text) //may be NULL!! + output = text; + else + output.clear(); + return true; + } + } + + return false; +} + + +bool XmlInput::readXmlElementValue(int& output, const TiXmlElement* parent, const string& name) +{ + string temp; + if (readXmlElementValue(temp, parent, name)) + { + output = stringToInt(temp); + return true; + } + else + return false; +} + + +bool XmlInput::readXmlElementValue(CompareVariant& output, const TiXmlElement* parent, const string& name) +{ + int dummy = 0; + if (readXmlElementValue(dummy, parent, name)) + { + output = CompareVariant(dummy); + return true; + } + else + return false; +} + + +bool XmlInput::readXmlElementValue(SyncDirection& output, const TiXmlElement* parent, const string& name) +{ + string dummy; + if (readXmlElementValue(dummy, parent, name)) + { + if (dummy == "left") + output = SYNC_DIR_LEFT; + else if (dummy == "right") + output = SYNC_DIR_RIGHT; + else //treat all other input as "none" + output = SYNC_DIR_NONE; + + return true; + } + else + return false; +} + + +bool XmlInput::readXmlElementValue(bool& output, const TiXmlElement* parent, const string& name) +{ + string dummy; + if (readXmlElementValue(dummy, parent, name)) + { + output = (dummy == "true"); + return true; + } + else + return false; +} + + +bool XmlInput::readXmlMainConfig(XmlMainConfig& outputCfg) +{ + TiXmlElement* root = doc.RootElement(); + if (!root) return false; + + TiXmlHandle hRoot(root); + + TiXmlElement* cmpSettings = hRoot.FirstChild("MainConfig").FirstChild("Comparison").ToElement(); + TiXmlElement* syncConfig = hRoot.FirstChild("MainConfig").FirstChild("Synchronization").FirstChild("Directions").ToElement(); + TiXmlElement* miscSettings = hRoot.FirstChild("MainConfig").FirstChild("Miscellaneous").ToElement(); + TiXmlElement* filter = TiXmlHandle(miscSettings).FirstChild("Filter").ToElement(); + + if (!cmpSettings || !syncConfig || !miscSettings || !filter) + return false; + + string tempString; +//########################################################### + //read compare variant + if (!readXmlElementValue(outputCfg.cfg.compareVar, cmpSettings, "Variant")) return false; + + //read folder pair(s) + TiXmlElement* folderPair = TiXmlHandle(cmpSettings).FirstChild("Folders").FirstChild("Pair").ToElement(); + + //read folder pairs + while (folderPair) + { + FolderPair newPair; + + if (!readXmlElementValue(tempString, folderPair, "Left")) return false; + newPair.leftDirectory = wxString::FromUTF8(tempString.c_str()); + + if (!readXmlElementValue(tempString, folderPair, "Right")) return false; + newPair.rightDirectory = wxString::FromUTF8(tempString.c_str()); + + outputCfg.directoryPairs.push_back(newPair); + folderPair = folderPair->NextSiblingElement(); + } + +//########################################################### + //read sync configuration + if (!readXmlElementValue(outputCfg.cfg.syncConfiguration.exLeftSideOnly, syncConfig, "LeftOnly")) return false; + if (!readXmlElementValue(outputCfg.cfg.syncConfiguration.exRightSideOnly, syncConfig, "RightOnly")) return false; + if (!readXmlElementValue(outputCfg.cfg.syncConfiguration.leftNewer, syncConfig, "LeftNewer")) return false; + if (!readXmlElementValue(outputCfg.cfg.syncConfiguration.rightNewer, syncConfig, "RightNewer")) return false; + if (!readXmlElementValue(outputCfg.cfg.syncConfiguration.different, syncConfig, "Different")) return false; +//########################################################### + //read filter settings + if (!readXmlElementValue(outputCfg.cfg.filterIsActive, filter, "Active")) return false; + + if (!readXmlElementValue(tempString, filter, "Include")) return false; + outputCfg.cfg.includeFilter = wxString::FromUTF8(tempString.c_str()); + + if (!readXmlElementValue(tempString, filter, "Exclude")) return false; + outputCfg.cfg.excludeFilter = wxString::FromUTF8(tempString.c_str()); +//########################################################### + //other + if (!readXmlElementValue(outputCfg.cfg.useRecycleBin, miscSettings, "Recycler")) return false; + if (!readXmlElementValue(outputCfg.cfg.continueOnError, miscSettings, "Continue")) return false; + + return true; +} + + +bool XmlInput::readXmlGuiConfig(XmlGuiConfig& outputCfg) +{ + TiXmlElement* root = doc.RootElement(); + if (!root) return false; + + TiXmlHandle hRoot(root); + + //read GUI layout + TiXmlElement* mainWindow = hRoot.FirstChild("GuiConfig").FirstChild("Windows").FirstChild("Main").ToElement(); + if (mainWindow) + { + if (!readXmlElementValue(outputCfg.hideFilteredElements, mainWindow, "HideFiltered")) + outputCfg.hideFilteredElements = false; + + //read application window size and position + if (!readXmlElementValue(outputCfg.widthNotMaximized, mainWindow, "Width")) + outputCfg.widthNotMaximized = -1; + if (!readXmlElementValue(outputCfg.heightNotMaximized, mainWindow, "Height")) + outputCfg.heightNotMaximized = -1; + if (!readXmlElementValue(outputCfg.posXNotMaximized, mainWindow, "PosX")) + outputCfg.posXNotMaximized = -1; + if (!readXmlElementValue(outputCfg.posYNotMaximized, mainWindow, "PosY")) + outputCfg.posYNotMaximized = -1; + if (!readXmlElementValue(outputCfg.isMaximized, mainWindow, "Maximized")) + outputCfg.isMaximized = false; + +//########################################################### + //read column widths + TiXmlElement* leftColumn = TiXmlHandle(mainWindow).FirstChild("LeftColumns").FirstChild("Width").ToElement(); + while (leftColumn) + { + const char* width = leftColumn->GetText(); + if (width) //may be NULL!! + outputCfg.columnWidthLeft.push_back(stringToInt(width)); + else + break; + + leftColumn = leftColumn->NextSiblingElement(); + } + + TiXmlElement* rightColumn = TiXmlHandle(mainWindow).FirstChild("RightColumns").FirstChild("Width").ToElement(); + while (rightColumn) + { + const char* width = rightColumn->GetText(); + if (width) //may be NULL!! + outputCfg.columnWidthRight.push_back(stringToInt(width)); + else + break; + + rightColumn = rightColumn->NextSiblingElement(); + } + } + + return true; +} + + +bool XmlInput::readXmlBatchConfig(XmlBatchConfig& outputCfg) +{ + TiXmlElement* root = doc.RootElement(); + if (!root) return false; + + TiXmlHandle hRoot(root); + + //read batch settings + TiXmlElement* batchConfig = hRoot.FirstChild("BatchConfig").ToElement(); + if (batchConfig) + { + //read application window size and position + if (!readXmlElementValue(outputCfg.silent, batchConfig, "Silent")) + outputCfg.silent = false; + } + + return true; +} + + +XmlOutput::XmlOutput(const wxString& fileName, const XmlType type) : + m_fileName(fileName) +{ + TiXmlBase::SetCondenseWhiteSpace(false); //do not condense whitespace characters + + TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", ""); //delete won't be necessary later; ownership passed to TiXmlDocument! + doc.LinkEndChild(decl); + + TiXmlElement* root = new TiXmlElement("FreeFileSync"); + if (type == XML_GUI_CONFIG) + root->SetAttribute("XmlType", "GUI"); //xml configuration type + else if (type == XML_BATCH_CONFIG) + root->SetAttribute("XmlType", "BATCH"); + else + assert(false); + doc.LinkEndChild(root); +} + + +bool XmlOutput::writeToFile() +{ + //workaround to get a FILE* from a unicode filename + wxFFile dummyFile(m_fileName, wxT("wb")); + if (!dummyFile.IsOpened()) + return false; + + FILE* outputFile = dummyFile.fp(); + + return doc.SaveFile(outputFile); //save XML +} + + +void XmlOutput::addXmlElement(TiXmlElement* parent, const string& name, const string& value) +{ + if (parent) + { + TiXmlElement* subElement = new TiXmlElement(name); + parent->LinkEndChild(subElement); + subElement->LinkEndChild(new TiXmlText(value)); + } +} + + +void XmlOutput::addXmlElement(TiXmlElement* parent, const string& name, const int value) +{ + addXmlElement(parent, name, numberToString(value)); +} + + +void XmlOutput::addXmlElement(TiXmlElement* parent, const string& name, const SyncDirection value) +{ + if (value == SYNC_DIR_LEFT) + addXmlElement(parent, name, string("left")); + else if (value == SYNC_DIR_RIGHT) + addXmlElement(parent, name, string("right")); + else if (value == SYNC_DIR_NONE) + addXmlElement(parent, name, string("none")); + else + assert(false); +} + + +void XmlOutput::addXmlElement(TiXmlElement* parent, const string& name, const bool value) +{ + if (value) + addXmlElement(parent, name, string("true")); + else + addXmlElement(parent, name, string("false")); +} + + +bool XmlOutput::writeXmlMainConfig(const XmlMainConfig& inputCfg) +{ + TiXmlElement* root = doc.RootElement(); + if (!root) return false; + + TiXmlElement* settings = new TiXmlElement("MainConfig"); + root->LinkEndChild(settings); + +//########################################################### + TiXmlElement* cmpSettings = new TiXmlElement("Comparison"); + settings->LinkEndChild(cmpSettings); + + //write compare algorithm + addXmlElement(cmpSettings, "Variant", inputCfg.cfg.compareVar); + + //write folder pair(s) + TiXmlElement* folders = new TiXmlElement("Folders"); + cmpSettings->LinkEndChild(folders); + + //write folder pairs + for (vector<FolderPair>::const_iterator i = inputCfg.directoryPairs.begin(); i != inputCfg.directoryPairs.end(); ++i) + { + TiXmlElement* folderPair = new TiXmlElement("Pair"); + folders->LinkEndChild(folderPair); + + addXmlElement(folderPair, "Left", string((i->leftDirectory).ToUTF8())); + addXmlElement(folderPair, "Right", string((i->rightDirectory).ToUTF8())); + } + +//########################################################### + TiXmlElement* syncSettings = new TiXmlElement("Synchronization"); + settings->LinkEndChild(syncSettings); + + //write sync configuration + TiXmlElement* syncConfig = new TiXmlElement("Directions"); + syncSettings->LinkEndChild(syncConfig); + + addXmlElement(syncConfig, "LeftOnly", inputCfg.cfg.syncConfiguration.exLeftSideOnly); + addXmlElement(syncConfig, "RightOnly", inputCfg.cfg.syncConfiguration.exRightSideOnly); + addXmlElement(syncConfig, "LeftNewer", inputCfg.cfg.syncConfiguration.leftNewer); + addXmlElement(syncConfig, "RightNewer", inputCfg.cfg.syncConfiguration.rightNewer); + addXmlElement(syncConfig, "Different", inputCfg.cfg.syncConfiguration.different); + +//########################################################### + TiXmlElement* miscSettings = new TiXmlElement("Miscellaneous"); + settings->LinkEndChild(miscSettings); + + //write filter settings + TiXmlElement* filter = new TiXmlElement("Filter"); + miscSettings->LinkEndChild(filter); + + addXmlElement(filter, "Active", inputCfg.cfg.filterIsActive); + addXmlElement(filter, "Include", string((inputCfg.cfg.includeFilter).ToUTF8())); + addXmlElement(filter, "Exclude", string((inputCfg.cfg.excludeFilter).ToUTF8())); + + //other + addXmlElement(miscSettings, "Recycler", inputCfg.cfg.useRecycleBin); + addXmlElement(miscSettings, "Continue", inputCfg.cfg.continueOnError); +//########################################################### + + return true; +} + + +bool XmlOutput::writeXmlGuiConfig(const XmlGuiConfig& inputCfg) +{ + TiXmlElement* root = doc.RootElement(); + if (!root) return false; + + TiXmlElement* guiLayout = new TiXmlElement("GuiConfig"); + root->LinkEndChild(guiLayout); + + TiXmlElement* windows = new TiXmlElement("Windows"); + guiLayout->LinkEndChild(windows); + + TiXmlElement* mainWindow = new TiXmlElement("Main"); + windows->LinkEndChild(mainWindow); + + addXmlElement(mainWindow, "HideFiltered", inputCfg.hideFilteredElements); + + //window size + addXmlElement(mainWindow, "Width", inputCfg.widthNotMaximized); + addXmlElement(mainWindow, "Height", inputCfg.heightNotMaximized); + + //window position + addXmlElement(mainWindow, "PosX", inputCfg.posXNotMaximized); + addXmlElement(mainWindow, "PosY", inputCfg.posYNotMaximized); + addXmlElement(mainWindow, "Maximized", inputCfg.isMaximized); + + //write column sizes + TiXmlElement* leftColumn = new TiXmlElement("LeftColumns"); + mainWindow->LinkEndChild(leftColumn); + + for (unsigned int i = 0; i < inputCfg.columnWidthLeft.size(); ++i) + addXmlElement(leftColumn, "Width", inputCfg.columnWidthLeft[i]); + + TiXmlElement* rightColumn = new TiXmlElement("RightColumns"); + mainWindow->LinkEndChild(rightColumn); + + for (unsigned int i = 0; i < inputCfg.columnWidthRight.size(); ++i) + addXmlElement(rightColumn, "Width", inputCfg.columnWidthRight[i]); + + return true; +} + + +bool XmlOutput::writeXmlBatchConfig(const XmlBatchConfig& inputCfg) +{ + TiXmlElement* root = doc.RootElement(); + if (!root) return false; + + TiXmlElement* batchConfig = new TiXmlElement("BatchConfig"); + root->LinkEndChild(batchConfig); + + addXmlElement(batchConfig, "Silent", inputCfg.silent); + + return true; +} diff --git a/library/processXml.h b/library/processXml.h new file mode 100644 index 00000000..d30cf49f --- /dev/null +++ b/library/processXml.h @@ -0,0 +1,114 @@ +#ifndef PROCESSXML_H_INCLUDED +#define PROCESSXML_H_INCLUDED + +#include "../FreeFileSync.h" +#include "tinyxml/tinyxml.h" + +namespace xmlAccess +{ + enum XmlType + { + XML_GUI_CONFIG, + XML_BATCH_CONFIG, + XML_OTHER + }; + + + struct XmlMainConfig + { + MainConfiguration cfg; + vector<FolderPair> directoryPairs; + }; + + + struct XmlGuiConfig + { + XmlGuiConfig() : + hideFilteredElements(false), //initialize values + widthNotMaximized(-1), + heightNotMaximized(-1), + posXNotMaximized(-1), + posYNotMaximized(-1), + isMaximized(false) {} + bool hideFilteredElements; + int widthNotMaximized; + int heightNotMaximized; + int posXNotMaximized; + int posYNotMaximized; + bool isMaximized; + vector<int> columnWidthLeft; + vector<int> columnWidthRight; + }; + + + struct XmlBatchConfig + { + XmlBatchConfig() : silent(false) {} + + bool silent; + }; + + + XmlType getXmlType(const wxString& filename); + + class XmlInput + { + public: + XmlInput(const wxString& fileName, const XmlType type); + ~XmlInput() {} + + bool loadedSuccessfully() + { + return loadSuccess; + } + + //read basic FreefileSync settings (used by commandline and GUI), return true if ALL values have been retrieved successfully + bool readXmlMainConfig(XmlMainConfig& outputCfg); + //read additional gui settings, all values retrieved are optional, so check for initial values! (== -1) + bool readXmlGuiConfig(XmlGuiConfig& outputCfg); + //read additional batch settings, all values retrieved are optional + bool readXmlBatchConfig(XmlBatchConfig& outputCfg); + + private: +//read + bool readXmlElementValue(string& output, const TiXmlElement* parent, const string& name); + bool readXmlElementValue(int& output, const TiXmlElement* parent, const string& name); + bool readXmlElementValue(CompareVariant& output, const TiXmlElement* parent, const string& name); + bool readXmlElementValue(SyncDirection& output, const TiXmlElement* parent, const string& name); + bool readXmlElementValue(bool& output, const TiXmlElement* parent, const string& name); + + TiXmlDocument doc; + bool loadSuccess; + }; + + + class XmlOutput + { + public: + XmlOutput(const wxString& fileName, const XmlType type); + ~XmlOutput() {} + + bool writeToFile(); + + //write basic FreefileSync settings (used by commandline and GUI), return true if everything was written successfully + bool writeXmlMainConfig(const XmlMainConfig& inputCfg); + //write additional gui settings + bool writeXmlGuiConfig(const XmlGuiConfig& inputCfg); + //write additional batch settings + bool writeXmlBatchConfig(const XmlBatchConfig& inputCfg); + + private: +//write + void addXmlElement(TiXmlElement* parent, const string& name, const string& value); + void addXmlElement(TiXmlElement* parent, const string& name, const int value); + void addXmlElement(TiXmlElement* parent, const string& name, const SyncDirection value); + void addXmlElement(TiXmlElement* parent, const string& name, const bool value); + + TiXmlDocument doc; + const wxString& m_fileName; + }; + +} + + +#endif // PROCESSXML_H_INCLUDED diff --git a/library/resources.cpp b/library/resources.cpp index d2dc36e8..9fce4501 100644 --- a/library/resources.cpp +++ b/library/resources.cpp @@ -6,9 +6,9 @@ #include "globalFunctions.h" #ifdef FFS_WIN -wxChar GlobalResources::fileNameSeparator = '\\'; +const wxChar GlobalResources::fileNameSeparator = '\\'; #elif defined FFS_LINUX -wxChar GlobalResources::fileNameSeparator = '/'; +const wxChar GlobalResources::fileNameSeparator = '/'; #else assert(false); #endif @@ -17,154 +17,108 @@ assert(false); const wxChar* GlobalResources::decimalPoint = wxEmptyString; const wxChar* GlobalResources::thousandsSeparator = wxEmptyString; +GlobalResources globalResource; //init resources on program startup -//command line parameters -const wxChar* GlobalResources::paramCompare = wxT("comp"); -const wxChar* GlobalResources::paramSync = wxT("sync"); -const wxChar* GlobalResources::paramInclude = wxT("incl"); -const wxChar* GlobalResources::paramExclude = wxT("excl"); -const wxChar* GlobalResources::paramContinueError = wxT("continue"); -const wxChar* GlobalResources::paramRecycler = wxT("recycler"); -const wxChar* GlobalResources::paramSilent = wxT("silent"); - -const wxChar* GlobalResources::valueSizeDate = wxT("SIZEDATE"); -const wxChar* GlobalResources::valueContent = wxT("CONTENT"); - +GlobalResources::GlobalResources() +{ + //map, allocate and initialize pictures + bitmapResource[wxT("left arrow.png")] = (bitmapArrowLeft = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("right arrow.png")] = (bitmapArrowRight = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("left arrow create.png")] = (bitmapArrowLeftCr = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("right arrow create.png")] = (bitmapArrowRightCr = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("no arrow.png")] = (bitmapArrowNone = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("start sync.png")] = (bitmapStartSync = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("start sync dis.png")] = (bitmapStartSyncDis = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("left delete.png")] = (bitmapDeleteLeft = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("right delete.png")] = (bitmapDeleteRight = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("email.png")] = (bitmapEmail = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("about.png")] = (bitmapAbout = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("website.png")] = (bitmapWebsite = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("exit.png")] = (bitmapExit = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("sync.png")] = (bitmapSync = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("compare.png")] = (bitmapCompare = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("sync disabled.png")] = (bitmapSyncDisabled = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("swap.png")] = (bitmapSwap = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("help.png")] = (bitmapHelp = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftOnly.png")] = (bitmapLeftOnly = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftNewer.png")] = (bitmapLeftNewer = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("different.png")] = (bitmapDifferent = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightNewer.png")] = (bitmapRightNewer = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightOnly.png")] = (bitmapRightOnly = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftOnlyDeact.png")] = (bitmapLeftOnlyDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftNewerDeact.png")] = (bitmapLeftNewerDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("differentDeact.png")] = (bitmapDifferentDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightNewerDeact.png")] = (bitmapRightNewerDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightOnlyDeact.png")] = (bitmapRightOnlyDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("equal.png")] = (bitmapEqual = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("equalDeact.png")] = (bitmapEqualDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("include.png")] = (bitmapInclude = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("exclude.png")] = (bitmapExclude = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("filter active.png")] = (bitmapFilterOn = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("filter not active.png")] = (bitmapFilterOff = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("warning.png")] = (bitmapWarning = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("small arrow up.png"]) = (bitmapSmallUp = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("small arrow down.png")] = (bitmapSmallDown = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("save.png")] = (bitmapSave = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("FFS.png")] = (bitmapFFS = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("deleteFile.png")] = (bitmapDeleteFile = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("gpl.png")] = (bitmapGPL = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusPause.png")] = (bitmapStatusPause = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusError.png")] = (bitmapStatusError = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusSuccess.png")] = (bitmapStatusSuccess = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusWarning.png")] = (bitmapStatusWarning = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusScanning.png")] = (bitmapStatusScanning = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusComparing.png")] = (bitmapStatusComparing = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusSyncing.png")] = (bitmapStatusSyncing = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("logo.png")] = (bitmapLogo = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("finished.png")] = (bitmapFinished = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusEdge.png")] = (bitmapStatusEdge = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("add pair.png")] = (bitmapAddFolderPair = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("remove pair.png")] = (bitmapRemoveFolderPair = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("remove pair disabl.png")] = (bitmapRemoveFolderPairD = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("link.png")] = (bitmapLink = new wxBitmap(wxNullBitmap)); + + //init all the other resource files + animationMoney = new wxAnimation(wxNullAnimation); + animationSync = new wxAnimation(wxNullAnimation); +} -map<wxString, wxBitmap*> GlobalResources::bitmapResource; -wxBitmap* GlobalResources::bitmapArrowLeft = 0; -wxBitmap* GlobalResources::bitmapArrowRight = 0; -wxBitmap* GlobalResources::bitmapArrowLeftCr = 0; -wxBitmap* GlobalResources::bitmapArrowRightCr = 0; -wxBitmap* GlobalResources::bitmapArrowNone = 0; -wxBitmap* GlobalResources::bitmapStartSync = 0; -wxBitmap* GlobalResources::bitmapStartSyncDis = 0; -wxBitmap* GlobalResources::bitmapDeleteLeft = 0; -wxBitmap* GlobalResources::bitmapDeleteRight = 0; -wxBitmap* GlobalResources::bitmapEmail = 0; -wxBitmap* GlobalResources::bitmapAbout = 0; -wxBitmap* GlobalResources::bitmapWebsite = 0; -wxBitmap* GlobalResources::bitmapExit = 0; -wxBitmap* GlobalResources::bitmapSync = 0; -wxBitmap* GlobalResources::bitmapCompare = 0; -wxBitmap* GlobalResources::bitmapSyncDisabled = 0; -wxBitmap* GlobalResources::bitmapSwap = 0; -wxBitmap* GlobalResources::bitmapHelp = 0; -wxBitmap* GlobalResources::bitmapLeftOnly = 0; -wxBitmap* GlobalResources::bitmapLeftNewer = 0; -wxBitmap* GlobalResources::bitmapDifferent = 0; -wxBitmap* GlobalResources::bitmapRightNewer = 0; -wxBitmap* GlobalResources::bitmapRightOnly = 0; -wxBitmap* GlobalResources::bitmapLeftOnlyDeact = 0; -wxBitmap* GlobalResources::bitmapLeftNewerDeact = 0; -wxBitmap* GlobalResources::bitmapDifferentDeact = 0; -wxBitmap* GlobalResources::bitmapRightNewerDeact = 0; -wxBitmap* GlobalResources::bitmapRightOnlyDeact = 0; -wxBitmap* GlobalResources::bitmapEqual = 0; -wxBitmap* GlobalResources::bitmapEqualDeact = 0; -wxBitmap* GlobalResources::bitmapInclude = 0; -wxBitmap* GlobalResources::bitmapExclude = 0; -wxBitmap* GlobalResources::bitmapFilterOn = 0; -wxBitmap* GlobalResources::bitmapFilterOff = 0; -wxBitmap* GlobalResources::bitmapWarning = 0; -wxBitmap* GlobalResources::bitmapSmallUp = 0; -wxBitmap* GlobalResources::bitmapSmallDown = 0; -wxBitmap* GlobalResources::bitmapSave = 0; -wxBitmap* GlobalResources::bitmapFFS = 0; -wxBitmap* GlobalResources::bitmapDeleteFile = 0; -wxBitmap* GlobalResources::bitmapGPL = 0; -wxBitmap* GlobalResources::bitmapStatusPause = 0; -wxBitmap* GlobalResources::bitmapStatusError = 0; -wxBitmap* GlobalResources::bitmapStatusSuccess = 0; -wxBitmap* GlobalResources::bitmapStatusWarning = 0; -wxBitmap* GlobalResources::bitmapStatusScanning = 0; -wxBitmap* GlobalResources::bitmapStatusComparing = 0; -wxBitmap* GlobalResources::bitmapStatusSyncing = 0; -wxBitmap* GlobalResources::bitmapLogo = 0; -wxBitmap* GlobalResources::bitmapFinished = 0; -wxBitmap* GlobalResources::bitmapStatusEdge = 0; +GlobalResources::~GlobalResources() +{ + //free bitmap resources + for (map<wxString, wxBitmap*>::iterator i = bitmapResource.begin(); i != bitmapResource.end(); ++i) + delete i->second; -wxAnimation* GlobalResources::animationMoney = 0; -wxAnimation* GlobalResources::animationSync = 0; -wxIcon* GlobalResources::programIcon = 0; + //free other resources + delete animationMoney; + delete animationSync; + delete programIcon; +} -void GlobalResources::loadResourceFiles() +void GlobalResources::load() { - //map, allocate and initialize pictures - bitmapResource[wxT("left arrow.png")] = (bitmapArrowLeft = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("right arrow.png")] = (bitmapArrowRight = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("left arrow create.png")] = (bitmapArrowLeftCr = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("right arrow create.png")]= (bitmapArrowRightCr = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("no arrow.png")] = (bitmapArrowNone = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("start sync.png")] = (bitmapStartSync = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("start sync dis.png")] = (bitmapStartSyncDis = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("left delete.png")] = (bitmapDeleteLeft = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("right delete.png")] = (bitmapDeleteRight = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("email.png")] = (bitmapEmail = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("about.png")] = (bitmapAbout = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("website.png")] = (bitmapWebsite = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("exit.png")] = (bitmapExit = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("sync.png")] = (bitmapSync = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("compare.png")] = (bitmapCompare = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("sync disabled.png")] = (bitmapSyncDisabled = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("swap.png")] = (bitmapSwap = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("help.png")] = (bitmapHelp = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("leftOnly.png")] = (bitmapLeftOnly = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("leftNewer.png")] = (bitmapLeftNewer = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("different.png")] = (bitmapDifferent = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("rightNewer.png")] = (bitmapRightNewer = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("rightOnly.png")] = (bitmapRightOnly = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("leftOnlyDeact.png")] = (bitmapLeftOnlyDeact = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("leftNewerDeact.png")] = (bitmapLeftNewerDeact = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("differentDeact.png")] = (bitmapDifferentDeact = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("rightNewerDeact.png")] = (bitmapRightNewerDeact = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("rightOnlyDeact.png")] = (bitmapRightOnlyDeact = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("equal.png")] = (bitmapEqual = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("equalDeact.png")] = (bitmapEqualDeact = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("include.png")] = (bitmapInclude = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("exclude.png")] = (bitmapExclude = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("filter active.png")] = (bitmapFilterOn = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("filter not active.png")] = (bitmapFilterOff = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("warning.png")] = (bitmapWarning = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("small arrow up.png"]) = (bitmapSmallUp = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("small arrow down.png")] = (bitmapSmallDown = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("save.png")] = (bitmapSave = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("FFS.png")] = (bitmapFFS = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("deleteFile.png")] = (bitmapDeleteFile = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("gpl.png")] = (bitmapGPL = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusPause.png")] = (bitmapStatusPause = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusError.png")] = (bitmapStatusError = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusSuccess.png")] = (bitmapStatusSuccess = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusWarning.png")] = (bitmapStatusWarning = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusScanning.png")] = (bitmapStatusScanning = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusComparing.png")] = (bitmapStatusComparing = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusSyncing.png")] = (bitmapStatusSyncing = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("logo.png")] = (bitmapLogo = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("finished.png")] = (bitmapFinished = new wxBitmap(wxNullBitmap)); - bitmapResource[wxT("statusEdge.png")] = (bitmapStatusEdge = new wxBitmap(wxNullBitmap)); - wxFileInputStream input(wxT("Resources.dat")); - if (!input.IsOk()) throw RuntimeException(_("Unable to load Resources.dat!")); + if (input.IsOk()) //if not... we don't want to react too harsh here + { + //activate support for .png files + wxImage::AddHandler(new wxPNGHandler); - wxZipInputStream resourceFile(input); + wxZipInputStream resourceFile(input); - wxZipEntry* entry; - map<wxString, wxBitmap*>::iterator bmp; - while ((entry = resourceFile.GetNextEntry())) - { - wxString name = entry->GetName(); + wxZipEntry* entry; + map<wxString, wxBitmap*>::iterator bmp; + while ((entry = resourceFile.GetNextEntry())) + { + wxString name = entry->GetName(); - //just to be sure: search if entry is available in map - if ((bmp = bitmapResource.find(name)) != bitmapResource.end()) - *(bmp->second) = wxBitmap(wxImage(resourceFile, wxBITMAP_TYPE_PNG)); + //just to be sure: search if entry is available in map + if ((bmp = bitmapResource.find(name)) != bitmapResource.end()) + *(bmp->second) = wxBitmap(wxImage(resourceFile, wxBITMAP_TYPE_PNG)); + } } - //load all the other resource files - animationMoney = new wxAnimation(wxNullAnimation); - animationSync = new wxAnimation(wxNullAnimation); - animationMoney->LoadFile(wxT("Resources.a01")); animationSync->LoadFile(wxT("Resources.a02")); @@ -175,16 +129,3 @@ void GlobalResources::loadResourceFiles() programIcon = new wxIcon(FreeFileSync_xpm); #endif } - - -void GlobalResources::unloadResourceFiles() -{ - //free bitmap resources - for (map<wxString, wxBitmap*>::iterator i = bitmapResource.begin(); i != bitmapResource.end(); ++i) - delete i->second; - - //free other resources - delete animationMoney; - delete animationSync; - delete programIcon; -} diff --git a/library/resources.h b/library/resources.h index 5f97e582..711c6038 100644 --- a/library/resources.h +++ b/library/resources.h @@ -11,89 +11,85 @@ using namespace std; class GlobalResources { public: - static void loadResourceFiles(); - static void unloadResourceFiles(); + GlobalResources(); + ~GlobalResources(); - static wxChar fileNameSeparator; + void load(); + + static const wxChar fileNameSeparator; //language dependent global variables: need to be initialized by CustomLocale on program startup and language switch static const wxChar* decimalPoint; static const wxChar* thousandsSeparator; - //command line parameters - static const wxChar* paramCompare; - static const wxChar* paramSync; - static const wxChar* paramInclude; - static const wxChar* paramExclude; - static const wxChar* paramContinueError; - static const wxChar* paramRecycler; - static const wxChar* paramSilent; - - static const wxChar* valueSizeDate; - static const wxChar* valueContent; - //image resource objects - static wxBitmap* bitmapArrowLeft; - static wxBitmap* bitmapArrowRight; - static wxBitmap* bitmapArrowLeftCr; - static wxBitmap* bitmapArrowRightCr; - static wxBitmap* bitmapArrowNone; - static wxBitmap* bitmapStartSync; - static wxBitmap* bitmapStartSyncDis; - static wxBitmap* bitmapDeleteLeft; - static wxBitmap* bitmapDeleteRight; - static wxBitmap* bitmapEmail; - static wxBitmap* bitmapAbout; - static wxBitmap* bitmapWebsite; - static wxBitmap* bitmapExit; - static wxBitmap* bitmapSync; - static wxBitmap* bitmapCompare; - static wxBitmap* bitmapSyncDisabled; - static wxBitmap* bitmapSwap; - static wxBitmap* bitmapHelp; - static wxBitmap* bitmapLeftOnly; - static wxBitmap* bitmapLeftNewer; - static wxBitmap* bitmapDifferent; - static wxBitmap* bitmapRightNewer; - static wxBitmap* bitmapRightOnly; - static wxBitmap* bitmapLeftOnlyDeact; - static wxBitmap* bitmapLeftNewerDeact; - static wxBitmap* bitmapDifferentDeact; - static wxBitmap* bitmapRightNewerDeact; - static wxBitmap* bitmapRightOnlyDeact; - static wxBitmap* bitmapEqual; - static wxBitmap* bitmapEqualDeact; - static wxBitmap* bitmapInclude; - static wxBitmap* bitmapExclude; - static wxBitmap* bitmapFilterOn; - static wxBitmap* bitmapFilterOff; - static wxBitmap* bitmapWarning; - static wxBitmap* bitmapSmallUp; - static wxBitmap* bitmapSmallDown; - static wxBitmap* bitmapSave; - static wxBitmap* bitmapFFS; - static wxBitmap* bitmapDeleteFile; - static wxBitmap* bitmapGPL; - static wxBitmap* bitmapStatusPause; - static wxBitmap* bitmapStatusError; - static wxBitmap* bitmapStatusSuccess; - static wxBitmap* bitmapStatusWarning; - static wxBitmap* bitmapStatusScanning; - static wxBitmap* bitmapStatusComparing; - static wxBitmap* bitmapStatusSyncing; - static wxBitmap* bitmapLogo; - static wxBitmap* bitmapFinished; - static wxBitmap* bitmapStatusEdge; + wxBitmap* bitmapArrowLeft; + wxBitmap* bitmapArrowRight; + wxBitmap* bitmapArrowLeftCr; + wxBitmap* bitmapArrowRightCr; + wxBitmap* bitmapArrowNone; + wxBitmap* bitmapStartSync; + wxBitmap* bitmapStartSyncDis; + wxBitmap* bitmapDeleteLeft; + wxBitmap* bitmapDeleteRight; + wxBitmap* bitmapEmail; + wxBitmap* bitmapAbout; + wxBitmap* bitmapWebsite; + wxBitmap* bitmapExit; + wxBitmap* bitmapSync; + wxBitmap* bitmapCompare; + wxBitmap* bitmapSyncDisabled; + wxBitmap* bitmapSwap; + wxBitmap* bitmapHelp; + wxBitmap* bitmapLeftOnly; + wxBitmap* bitmapLeftNewer; + wxBitmap* bitmapDifferent; + wxBitmap* bitmapRightNewer; + wxBitmap* bitmapRightOnly; + wxBitmap* bitmapLeftOnlyDeact; + wxBitmap* bitmapLeftNewerDeact; + wxBitmap* bitmapDifferentDeact; + wxBitmap* bitmapRightNewerDeact; + wxBitmap* bitmapRightOnlyDeact; + wxBitmap* bitmapEqual; + wxBitmap* bitmapEqualDeact; + wxBitmap* bitmapInclude; + wxBitmap* bitmapExclude; + wxBitmap* bitmapFilterOn; + wxBitmap* bitmapFilterOff; + wxBitmap* bitmapWarning; + wxBitmap* bitmapSmallUp; + wxBitmap* bitmapSmallDown; + wxBitmap* bitmapSave; + wxBitmap* bitmapFFS; + wxBitmap* bitmapDeleteFile; + wxBitmap* bitmapGPL; + wxBitmap* bitmapStatusPause; + wxBitmap* bitmapStatusError; + wxBitmap* bitmapStatusSuccess; + wxBitmap* bitmapStatusWarning; + wxBitmap* bitmapStatusScanning; + wxBitmap* bitmapStatusComparing; + wxBitmap* bitmapStatusSyncing; + wxBitmap* bitmapLogo; + wxBitmap* bitmapFinished; + wxBitmap* bitmapStatusEdge; + wxBitmap* bitmapAddFolderPair; + wxBitmap* bitmapRemoveFolderPair; + wxBitmap* bitmapRemoveFolderPairD; + wxBitmap* bitmapLink; - static wxAnimation* animationMoney; - static wxAnimation* animationSync; + wxAnimation* animationMoney; + wxAnimation* animationSync; - static wxIcon* programIcon; + wxIcon* programIcon; private: //resource mapping - static map<wxString, wxBitmap*> bitmapResource; + map<wxString, wxBitmap*> bitmapResource; }; +extern GlobalResources globalResource; //loads bitmap resources on program startup + #endif // RESOURCES_H_INCLUDED |