Пример #1
0
bool App::saveTree()
{
    // backup dir checking (see also preferences.cpp)
    if (preferences.saveBackupFile)
    {
        QDir backupDir(preferences.backupLocation);
        
        if (!backupDir.exists())
        {
            QMessageBox::critical(this, "Invalid directory", "Please, enter the existing\ndirectory in backup location.", 0, 0);
            return false;
        }
    }
    
    QFile saveF(Global::applicationFileName("iqnotes", currentFile + ".xml"));
    QFile rijnF(Global::applicationFileName("iqnotes", currentFile + ".rijn"));

    QString saveS;
    QTextStream saveData(saveS, IO_WriteOnly);
	saveData.setEncoding(saveData.UnicodeUTF8);
	
    saveData << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<iqnotes>\n"
    << "<config>\n"
    << "<backup save=\"" << (preferences.saveBackupFile ? "yes" : "no") << "\" location=\"" << preferences.backupLocation << "\"/>\n"
             << "<notes showreminder=\"" << (preferences.showReminder ? "yes" : "no") << "\" />\n"
    << "<security passwd=\"" << preferences.passwdHex << "\"/>\n"
    << "</config>\n"

    << "<entries>\n";

    for (Entry *e = entriesList->first(); e; e = entriesList->next())
    {
        saveData << "<entry name=\"" << quoteXML(e->getName()) << "\" defaultpic=\"" << quoteXML(e->getDefaultPic()) << "\">\n";

        for (PropertyStruct *ps = e->first(); ps; ps = e->next())
        {
            saveData << "<property name=\"" << quoteXML(ps->getName()) << "\" "
            << "type=\"" << (ps->getType() == PropertyStruct::ONE_LINE ? "oneLine" : "multiLine") << "\"/>\n";
        }

        saveData << "</entry>\n";
    }

    saveData << "</entries>\n";

    notes->saveTree(&saveData);

    saveData << "</iqnotes>\n";
	//SF.close();
    QCString dataUTF8 = saveS.utf8();

    if (!preferences.passwdHex.length())
    {
        saveF.open(IO_WriteOnly);

        QTextStream saveData1(&saveF);
		saveData1.setEncoding(saveData1.UnicodeUTF8);
		saveData1 << saveS;

        if (preferences.saveBackupFile)
        {
            QFile backupSaveF(preferences.backupLocation + "/" + currentFile + ".xml");
            QTextStream saveData2(&backupSaveF);
            backupSaveF.open(IO_WriteOnly);
            saveData2 << dataUTF8;
        }

        if (rijnF.exists())
            rijnF.remove();
    }
    else
    {
        Rijndael rijndael;
        unsigned char *rijnEncrypt = (unsigned char*)malloc(dataUTF8.length() + 16);

        rijnF.open(IO_WriteOnly);

        rijndael.init(Rijndael::CBC, Rijndael::Encrypt, preferences.passwd16Bin, Rijndael::Key16Bytes);
        int len = rijndael.padEncrypt((unsigned char*)(const char*)dataUTF8, dataUTF8.length(), rijnEncrypt);

        rijnF.writeBlock((const char *)rijnEncrypt, len);
        if (preferences.saveBackupFile)
        {
            QFile rijnBackupF(preferences.backupLocation + "/" + currentFile + ".rijn");
            rijnBackupF.open(IO_WriteOnly);
            rijnBackupF.writeBlock((const char *)rijnEncrypt, len);
        }

        free(rijnEncrypt);

        if (saveF.exists())
            saveF.remove();
    }

    return true;
}
void doLazyFixer(std::string pathIn,  std::string imgFileIn,
                std::string pathOut,
                LazyFixTool_Setup &setup)
{
    if(Files::hasSuffix(imgFileIn, "m.gif"))
        return; //Skip mask files

    std::string imgPathIn = pathIn + "/" + imgFileIn;
    std::string maskPathIn;

    std::cout << imgPathIn;
    std::cout.flush();

    std::string maskFileIn;
    getGifMask(maskFileIn, imgFileIn);

    maskPathIn = pathIn + "/" + maskFileIn;

    //Create backup in case of source and target are same
    if(!setup.noMakeBackup && (pathIn == pathOut))
    {
        DirMan backupDir(pathIn + "/_backup");
        bool ret = false;
        if(!backupDir.exists())
        {
            std::cout << ".MKDIR.";
            std::cout.flush();
            if(!backupDir.mkdir(""))
            {
                std::cout << ".FAIL!.";
                std::cout.flush();
                goto skipBackpDir;
            }
        }
        ret |= Files::copyFile(backupDir.absolutePath() + "/" + imgFileIn,  imgPathIn,  false);
        ret |= Files::copyFile(backupDir.absolutePath() + "/" + maskFileIn, maskPathIn, false);

        if(ret)
            setup.count_backups++;
        skipBackpDir:;
    }

    FIBITMAP *image = loadImage(imgPathIn);
    if(!image)
    {
        setup.count_failed++;
        std::cout << "...CAN'T OPEN!\n";
        std::cout.flush();
        return;
    }

    FIBITMAP *mask = NULL;
    if(Files::fileExists(maskPathIn))
    {
        bool hasMask = mergeBitBltToRGBA(image, maskPathIn);
        if(hasMask) // Split in case is mask presented
            splitRGBAtoBitBlt(image, mask);
    }

    bool isFail = false;
    if(image)
    {
        std::string outPathF = pathOut + "/" + imgFileIn;
        FIBITMAP *image8 = FreeImage_ColorQuantize(image, FIQ_WUQUANT);
        if(image8)
        {
            int ret = FreeImage_Save(FIF_GIF, image8, outPathF.c_str());
            if(!ret)
            {
                std::cout << "...F-WRT FAILED!\n";
                isFail = true;
            }
            FreeImage_Unload(image8);
        }
        else
            isFail = true;
        FreeImage_Unload(image);

    }
    else
    {
        isFail = true;
    }

    if(mask)
    {
        std::string outPathB = pathOut + "/" + maskFileIn;
        FIBITMAP *mask8  = FreeImage_ColorQuantize(mask, FIQ_WUQUANT);
        if(mask8)
        {
            int ret = FreeImage_Save(FIF_GIF, mask8, outPathB.c_str());
            if(!ret)
            {
                std::cout << "...B-WRT FAILED!\n";
                isFail = true;
            }
            FreeImage_Unload(mask8);
        }
        else
            isFail = true;
        FreeImage_Unload(mask);
    } else {
        setup.count_nomask++;
    }

    if(isFail)
    {
        setup.count_failed++;
        std::cout << "...FAILED!\n";
    } else {
        setup.count_success++;
        std::cout << "...done\n";
    }

    std::cout.flush();
}