示例#1
0
void TConfDlg::SaveConfig(const AnsiString &File) {

	HANDLE file;
    DWORD type,Written;
    int i;
    CHostRef *host;
    AnsiString FailedName="NONE";
    file = CreateFileA(File.c_str(),GENERIC_WRITE,0,0,CREATE_ALWAYS,
                     FILE_FLAG_SEQUENTIAL_SCAN,0);
    if(file == INVALID_HANDLE_VALUE) {
  	    Application->MessageBox("Cannot create file!","Error",MB_OK|MB_ICONERROR);
	    return;
    }

    // Remove the configuration from hosts
    // That do not have an individual configuration
    for(i =0;i<LastList->Count;++i) {
    	host = (CHostRef*)(LastList->Objects[i]);
        if(host) host->RemoveConfigRefs();
    }

    FailedName="MAGIC";
    type = MAGIC;
    if(!WriteFile(file,&type,sizeof(DWORD),&Written,0)) goto Remove;
    FailedName="FILE_VERSION";
    type = FILE_VERSION;
    if(!WriteFile(file,&type,sizeof(DWORD),&Written,0))  goto Remove;
    FailedName="Plugin";
    if(!WritePlugin(file,PluginManager.GetActualPlugin())) goto Remove;
    FailedName = "WriteConfigData";
    if(!WriteConfigData(file,&GlobalConfig)) goto Remove;
    FailedName="WriteHost";
	for(i=0;i<LastList->Count;++i) {
    	if(!WriteHost(file,(HostData*)*(CHostRef*)LastList->Objects[i]))
        	goto Remove;
    }
    //SI: 13.06.05 Write Account at last position
    //SI: 14.06.05 save without Write Account possible
    FailedName="WriteAccount";
    //if(!WriteAccount(file,&GlobalConfig)) goto Remove;
    if(!WriteAccount(file,&GlobalConfig))
      Application->MessageBox("Could not save account information in config!","Error",MB_ICONERROR|MB_OK);;

    type = TYPE_NONE;
    WriteFile(file,&type,sizeof(DWORD),&Written,0);
   	CloseHandle(file);

    for(i=0;i<LastList->Count;++i)  {
    	host=(CHostRef*)LastList->Objects[i];
        // If the host has no individual configuration then
        // set a reference to the global config.
        host->SetConfigRef(&GlobalConfig);
    }
    return;
Remove:
	CloseHandle(file);
    DeleteFileA(File.c_str());
    FailedName = FailedName + " failed. Could not save config!";
    Application->MessageBox(FailedName.c_str(),"Error",MB_ICONERROR|MB_OK);
	return;
}
示例#2
0
文件: generators.cpp 项目: dbb/loot
    void GenerateReportData(const Game& game,
        std::list<Message>& messages,
        const std::list<Plugin>& plugins,
        const std::string& masterlistVersion,
        const std::string& masterlistDate,
        const bool masterlistUpdateEnabled) {

        YAML::Node oldDetails;
        GetOldReportDetails(game.ReportDataPath(), oldDetails);
        
        //Need to output YAML as a JSON Javascript variable.
        YAML::Emitter yout;
        yout.SetOutputCharset(YAML::EscapeNonAscii);
        yout.SetStringFormat(YAML::DoubleQuoted);
        yout.SetBoolFormat(YAML::TrueFalseBool);
        yout.SetSeqFormat(YAML::Flow);
        yout.SetMapFormat(YAML::Flow);

        BOOST_LOG_TRIVIAL(debug) << "Generating JSON report data.";

        yout << YAML::BeginMap;

        yout << YAML::Key << "lootVersion"
            << YAML::Value << IntToString(g_version_major) + "." + IntToString(g_version_minor) + "." + IntToString(g_version_patch);

        yout << YAML::Key << "masterlist"
            << YAML::BeginMap
            << YAML::Key << "updaterEnabled"
            << YAML::Value;

        if (masterlistUpdateEnabled)
            yout << boost::locale::translate("Enabled").str();
        else
            yout << boost::locale::translate("Disabled").str();

        yout << YAML::Key << "revision"
            << YAML::Value << masterlistVersion
            << YAML::Key << "date"
            << YAML::Value << masterlistDate
            << YAML::EndMap;

        if (!plugins.empty()) {
            BOOST_LOG_TRIVIAL(debug) << "Generating JSON plugin data.";
            YAML::Emitter tempout;
            tempout.SetOutputCharset(YAML::EscapeNonAscii);
            tempout.SetStringFormat(YAML::DoubleQuoted);
            tempout.SetBoolFormat(YAML::TrueFalseBool);
            tempout.SetSeqFormat(YAML::Flow);
            tempout.SetMapFormat(YAML::Flow);

            tempout << YAML::BeginSeq;
            for (std::list<Plugin>::const_iterator it = plugins.begin(), endit = plugins.end(); it != endit; ++it) {
                WritePlugin(tempout, *it, game);
            }
            tempout << YAML::EndSeq;

            YAML::Node node = YAML::Load(tempout.c_str());

            if (AreDetailsEqual(node, oldDetails))
                messages.push_front(loot::Message(loot::Message::say, boost::locale::translate("There have been no changes in the Details tab since LOOT was last run for this game.").str()));
                
            //Need to generate output twice because passing the node causes !<!> to be written before every key and value for some reason.
            yout << YAML::Key << "plugins"
                << YAML::Value << YAML::BeginSeq;
            for (std::list<Plugin>::const_iterator it = plugins.begin(), endit = plugins.end(); it != endit; ++it) {
                WritePlugin(yout, *it, game);
            }
            yout << YAML::EndSeq;
        }
        else if (oldDetails.size() == 0)
            messages.push_front(loot::Message(loot::Message::say, boost::locale::translate("There have been no changes in the Details tab since LOOT was last run for this game.").str()));

        if (!messages.empty()) {
            BOOST_LOG_TRIVIAL(debug) << "Generating JSON general message data.";
            yout << YAML::Key << "globalMessages"
                << YAML::Value << YAML::BeginSeq;
            for (std::list<Message>::const_iterator it = messages.begin(), endit = messages.end(); it != endit; ++it) {
                WriteMessage(yout, *it);
            }
            yout << YAML::EndSeq;
        }

        BOOST_LOG_TRIVIAL(debug) << "Generating text translations.";
        yout << YAML::Key << "l10n"
            << YAML::BeginMap

            << YAML::Key << "txtSummarySec"
            << YAML::Value << boost::locale::translate("Summary").str()

            << YAML::Key << "txtSummary"
            << YAML::Value << boost::locale::translate("Summary").str()

            << YAML::Key << "txtLootVersion"
            << YAML::Value << boost::locale::translate("LOOT Version").str()

            << YAML::Key << "txtMasterlistRevision"
            << YAML::Value << boost::locale::translate("Masterlist Revision").str()

            << YAML::Key << "txtMasterlistDate"
            << YAML::Value << boost::locale::translate("Masterlist Date").str()

            << YAML::Key << "txtMasterlistUpdating"
            << YAML::Value << boost::locale::translate("Masterlist Updating").str()

            << YAML::Key << "txtTotalMessageNo"
            << YAML::Value << boost::locale::translate("Total Number of Messages").str()

            << YAML::Key << "txtTotalWarningNo"
            << YAML::Value << boost::locale::translate("Number of Warnings").str()

            << YAML::Key << "txtTotalErrorNo"
            << YAML::Value << boost::locale::translate("Number of Errors").str()

            << YAML::Key << "txtGeneralMessages"
            << YAML::Value << boost::locale::translate("General Messages").str()

            << YAML::Key << "txtDetailsSec"
            << YAML::Value << boost::locale::translate("Details").str()

            << YAML::Key << "filtersToggle"
            << YAML::Value << boost::locale::translate("Filters").str()

            << YAML::Key << "txtHideVersionNumbers"
            << YAML::Value << boost::locale::translate("Hide Version Numbers").str()

            << YAML::Key << "txtHideCRCs"
            << YAML::Value << boost::locale::translate("Hide CRCs").str()

            << YAML::Key << "txtHideBashTags"
            << YAML::Value << boost::locale::translate("Hide Bash Tag Suggestions").str()

            << YAML::Key << "txtHideNotes"
            << YAML::Value << boost::locale::translate("Hide Notes").str()

            << YAML::Key << "txtHideDoNotCleanMessages"
            << YAML::Value << boost::locale::translate("Hide 'Do Not Clean' Messages").str()

            << YAML::Key << "txtHideInactivePluginMessages"
            << YAML::Value << boost::locale::translate("Hide Inactive Plugin Messages").str()

            << YAML::Key << "txtHideAllPluginMessages"
            << YAML::Value << boost::locale::translate("Hide All Plugin Messages").str()

            << YAML::Key << "txtHideMessagelessPlugins"
            << YAML::Value << boost::locale::translate("Hide Messageless Plugins").str()

            << YAML::Key << "txtPluginsHidden"
            << YAML::Value << boost::locale::translate("Plugins hidden").str()

            << YAML::Key << "txtMessagesHidden"
            << YAML::Value << boost::locale::translate("Messages hidden").str()

            << YAML::EndMap;

        yout << YAML::EndMap;

        loot::ofstream out(game.ReportDataPath());
        out << "var data = " << yout.c_str();
        out.close();
    }