summaryrefslogtreecommitdiff
path: root/RealtimeSync/xml_ffs.cpp
blob: 32ef3b39f23832e8d3f0211f6e60eacb10334bc3 (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
// **************************************************************************
// * 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-2011 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************

#include "xml_ffs.h"
#include "../lib/ffs_paths.h"
#include <zen/zstring.h>
#include <wx+/string_conv.h>

//include FreeFileSync xml headers
#include "../lib/process_xml.h"

using namespace zen;


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

    std::set<Zstring, LessFilename> uniqueFolders;

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

    //additional folders
    std::for_each(batchCfg.mainCfg.additionalPairs.begin(), batchCfg.mainCfg.additionalPairs.end(),
                  [&](const FolderPairEnh & fp)
    {
        uniqueFolders.insert(fp.leftDirectory);
        uniqueFolders.insert(fp.rightDirectory);
    });

    uniqueFolders.erase(Zstring());

    output.directories.clear();
    std::transform(uniqueFolders.begin(), uniqueFolders.end(), std::back_inserter(output.directories),
    [](const Zstring & fn) { return toWx(fn); });

    output.commandline = wxT("\"") + zen::getLauncher() + wxT("\"") +
                         wxT(" \"") + filename + wxT("\"");

    return output;
}


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

    //convert batch config to RealtimeSync config
    xmlAccess::XmlBatchConfig batchCfg;
    try
    {
        xmlAccess::readConfig(filename, batchCfg); //throw xmlAccess::FfsXmlError;
    }
    catch (const xmlAccess::FfsXmlError& e)
    {
        if (e.getSeverity() == xmlAccess::FfsXmlError::WARNING)
            config = convertBatchToReal(batchCfg, toZ(filename)); //do work despite parsing errors, then re-throw

        throw;                                 //
    }
    config = convertBatchToReal(batchCfg, toZ(filename));
}


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

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

    return settings.programLanguage;
}
bgstack15