summaryrefslogtreecommitdiff
path: root/RealtimeSync/xmlFreeFileSync.cpp
blob: ac4c1e3a33fbc24e7996e3bbba9c0165d5641252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include "xmlFreeFileSync.h"
#include "../shared/standardPaths.h"
#include "../shared/globalFunctions.h"
#include "../shared/zstring.h"
#include "functions.h"
#include "../shared/xmlBase.h"
#include "../shared/stringConv.h"

//include FreeFileSync xml headers
#include "../library/processXml.h"

using namespace FreeFileSync;


#ifdef FFS_WIN
struct CmpNoCase
{
    bool operator()(const wxString& a, const wxString& b) const
    {
        return a.CmpNoCase(b) < 0;
    }
};
#endif


xmlAccess::XmlRealConfig convertBatchToReal(const xmlAccess::XmlBatchConfig& batchCfg, const wxString& filename)
{
    xmlAccess::XmlRealConfig output;

#ifdef FFS_WIN
    std::set<wxString, CmpNoCase> uniqueFolders;
#elif defined FFS_LINUX
    std::set<wxString> uniqueFolders;
#endif

    //add main folders
    uniqueFolders.insert(zToWx(batchCfg.mainCfg.firstPair.leftDirectory));
    uniqueFolders.insert(zToWx(batchCfg.mainCfg.firstPair.rightDirectory));

    //additional folders
    for (std::vector<FreeFileSync::FolderPairEnh>::const_iterator i = batchCfg.mainCfg.additionalPairs.begin();
            i != batchCfg.mainCfg.additionalPairs.end(); ++i)
    {
        uniqueFolders.insert(zToWx(i->leftDirectory));
        uniqueFolders.insert(zToWx(i->rightDirectory));
    }

    output.directories.insert(output.directories.end(), uniqueFolders.begin(), uniqueFolders.end());

    output.commandline = FreeFileSync::getBinaryDir() +
#ifdef FFS_WIN
                         wxT("FreeFileSync.exe") +
#elif defined FFS_LINUX
                         wxT("FreeFileSync") +
#endif
                         wxT(" \"") + filename + wxT("\"");

    return output;
}


void RealtimeSync::readRealOrBatchConfig(const wxString& filename, xmlAccess::XmlRealConfig& config)  //throw (xmlAccess::XmlError);
{
    if (xmlAccess::getXmlType(filename) != xmlAccess::XML_BATCH_CONFIG)
    {
        xmlAccess::readRealConfig(filename, config);
        return;
    }

    //convert batch config to RealtimeSync config
    xmlAccess::XmlBatchConfig batchCfg;
    try
    {
        xmlAccess::readBatchConfig(filename, batchCfg); //throw (xmlAccess::XmlError);
    }
    catch (const xmlAccess::XmlError& e)
    {
        if (e.getSeverity() != xmlAccess::XmlError::WARNING)
            throw;

        config = convertBatchToReal(batchCfg, filename); //do work despite parsing errors, then re-throw
        throw;                                 //
    }
    config = convertBatchToReal(batchCfg, filename);
}


int RealtimeSync::getProgramLanguage()
{
    xmlAccess::XmlGlobalSettings settings;

    try
    {
        xmlAccess::readGlobalSettings(settings);
    }
    catch (const xmlAccess::XmlError&)
        {} //user default language if error occured

    return settings.programLanguage;
}
bgstack15