QString sat::getTemplateTag()
{
	QString category = dia->catsCombo->currentText();
	if (category.isEmpty())
		category = QObject::tr("Own Templates");
	else
		category = dia->cats.key(category, category);
	QDate now = QDate::currentDate();
	QString cat = QString(category);
	replaceIllegalChars(cat);
	QString tag = "\t<template category=\""+cat+"\">\n";
	QString name = QString(dia->nameEdit->text());
	replaceIllegalChars(name);
	tag += "\t\t<name>"+name+"</name>\n";
	tag += "\t\t<file>"+file+"</file>\n";
	tag += "\t\t<tnail>"+name+"tn.png"+"</tnail>\n";
	tag += "\t\t<img>"+name+".png"+"</img>\n";
	QString psize = QString(dia->psizeEdit->text());
	replaceIllegalChars(psize);
	tag += "\t\t<psize>"+psize+"</psize>\n";
	QString colors = QString(dia->colorsEdit->text());
	replaceIllegalChars(colors);
	tag += "\t\t<color>"+colors+"</color>\n";
	QString descr = QString(dia->descrEdit->toPlainText());
	replaceIllegalChars(descr);
	tag += "\t\t<descr>"+descr+"</descr>\n";
	QString usage = QString(dia->usageEdit->toPlainText());
	replaceIllegalChars(usage);
	tag += "\t\t<usage>"+usage+"</usage>\n";
	QString scribus_version = QString(VERSION);
	replaceIllegalChars(scribus_version);
	tag += "\t\t<scribus_version>" + scribus_version + "</scribus_version>\n";
	QString date = QString(now.toString(Qt::ISODate));
	replaceIllegalChars(date);
	tag += "\t\t<date>" + date + "</date>\n";
	QString author = QString(dia->authorEdit->text());
	replaceIllegalChars(author);
	tag += "\t\t<author>"+author+"</author>\n";
	QString email = QString(dia->emailEdit->text());
	replaceIllegalChars(email);
	tag += "\t\t<email>"+email+"</email>\n";
	tag += "\t</template>\n";

	return tag;
}
Beispiel #2
0
void PrefsFile::writeContexts(ContextMap* contextMap, QTextStream& stream)
{
	ContextMap::Iterator it;
	for (it = contextMap->begin(); it != contextMap->end(); ++it)
	{
		if ((it.value()->isPersistent()) && (!it.value()->isEmpty()))
		{
			stream << "\t\t<context name=\"" + replaceIllegalChars(it.key()) + "\">\n";
			AttributeMap::Iterator it2;
			PrefsContext* tmpCon = it.value();
			for (it2 = tmpCon->values.begin(); it2 != tmpCon->values.end(); ++it2)
			{
				stream << "\t\t\t<attribute key=\"" + replaceIllegalChars(it2.key()) + "\" ";
				stream << "value=\""  + replaceIllegalChars(it2.value()) + "\"/>\n";
			}
			TableMap::Iterator it3;
			for (it3 = tmpCon->tables.begin(); it3 != tmpCon->tables.end(); ++it3)
			{
				stream << "\t\t\t<table name=\"" + replaceIllegalChars(it3.key()) + "\">\n";
				PrefsTable* t = it3.value();
				for (int i = 0; i < t->height(); ++i)
				{
					stream << QString("\t\t\t\t<row index=\"%1\">\n").arg(i);
					for (int j = 0; j < t->width(); ++j)
					{
						stream << QString("\t\t\t\t\t<col index=\"%1\">").arg(j);
						stream << replaceIllegalChars(t->get(i, j, "__NOT__SET__")) << "</col>\n";
					}
					stream << "\t\t\t\t</row>\n";
				}
				stream << "\t\t\t</table>\n";
			}
			stream << "\t\t</context>\n";
		}
	}
}
Beispiel #3
0
int createZIP(gameSave_t *save, device_t src)
{
    FILE *mcFile;
    zipFile zf;
    zip_fileinfo zfi;
    sceMcTblGetDir mcDir[64] __attribute__((aligned(64)));
    fio_stat_t stat;
    char mcPath[100];
    char zipPath[100];
    char filePath[150];
    char validName[32];
    char *data;
    int i;
    int ret;
    float progress = 0.0;
    
    if(!save || !(src & (MC_SLOT_1|MC_SLOT_2)))
        return 0;
    
    replaceIllegalChars(save->name, validName, '-');
    rtrim(validName);
    snprintf(zipPath, 100, "%s%s.zip", flashDriveDevice, validName);
    
    if(fioGetstat(zipPath, &stat) == 0)
    {
        const char *items[] = {"Yes", "No"};
        int choice = displayPromptMenu(items, 2, "Save already exists. Do you want to overwrite it?");
        
        if(choice == 1)
            return 0;
    }
    
    zf = zipOpen(zipPath, APPEND_STATUS_CREATE);
    if(!zf)
        return 0;
    
    snprintf(mcPath, 100, "%s/*", strstr(save->path, ":") + 1);
    
    mcGetDir((src == MC_SLOT_1) ? 0 : 1, 0, mcPath, 0, 54, mcDir);
    mcSync(0, NULL, &ret);
    
    for(i = 0; i < ret; i++)
    {
        if(mcDir[i].AttrFile & MC_ATTR_SUBDIR)
            continue;

        else if(mcDir[i].AttrFile & MC_ATTR_FILE)
        {
            progress += (float)1/(ret-2);
            drawCopyProgress(progress);

            snprintf(filePath, 100, "%s/%s", save->path, mcDir[i].EntryName);
            
            mcFile = fopen(filePath, "rb");
            data = malloc(mcDir[i].FileSizeByte);
            fread(data, 1, mcDir[i].FileSizeByte, mcFile);
            fclose(mcFile);

            if(zipOpenNewFileInZip(zf, strstr(filePath, ":") + 1, &zfi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION) == ZIP_OK)
            {
                zipWriteInFileInZip(zf, data, mcDir[i].FileSizeByte);
                zipCloseFileInZip(zf);
            }
            else
            {
                zipClose(zf, NULL);
                free(data);
                return 0;
            }

            free(data);
        }
    }

    zipClose(zf, NULL);

    return 1;
}
Beispiel #4
0
int createPSU(gameSave_t *save, device_t src)
{
    FILE *psuFile, *mcFile;
    sceMcTblGetDir mcDir[64] __attribute__((aligned(64)));
    McFsEntry dir, file;
    fio_stat_t stat;
    char mcPath[100];
    char psuPath[100];
    char filePath[150];
    char validName[32];
    char *data;
    int numFiles = 0;
    int i, j, padding;
    int ret;
    float progress = 0.0;
    
    if(!save || !(src & (MC_SLOT_1|MC_SLOT_2)))
        return 0;
    
    memset(&dir, 0, sizeof(McFsEntry));
    memset(&file, 0, sizeof(McFsEntry));
    
    replaceIllegalChars(save->name, validName, '-');
    rtrim(validName);
    snprintf(psuPath, 100, "%s%s.psu", flashDriveDevice, validName);
    
    if(fioGetstat(psuPath, &stat) == 0)
    {
        const char *items[] = {"Yes", "No"};
        int choice = displayPromptMenu(items, 2, "Save already exists. Do you want to overwrite it?");
        
        if(choice == 1)
            return 0;
    }
    
    psuFile = fopen(psuPath, "wb");
    if(!psuFile)
        return 0;
    
    snprintf(mcPath, 100, "%s/*", strstr(save->path, ":") + 1);
    
    mcGetDir((src == MC_SLOT_1) ? 0 : 1, 0, mcPath, 0, 54, mcDir);
    mcSync(0, NULL, &ret);
    
    // Leave space for 3 directory entries (root, '.', and '..').
    for(i = 0; i < 512*3; i++)
        fputc(0, psuFile);
    
    for(i = 0; i < ret; i++)
    {
        if(mcDir[i].AttrFile & MC_ATTR_SUBDIR)
        {
            dir.mode = 0x8427;
            memcpy(&dir.created, &mcDir[i]._Create, sizeof(sceMcStDateTime));
            memcpy(&dir.modified, &mcDir[i]._Modify, sizeof(sceMcStDateTime));
        }
        
        else if(mcDir[i].AttrFile & MC_ATTR_FILE)
        {
            progress += (float)1/(ret-2);
            drawCopyProgress(progress);
            
            file.mode = mcDir[i].AttrFile;
            file.length = mcDir[i].FileSizeByte;
            memcpy(&file.created, &mcDir[i]._Create, sizeof(sceMcStDateTime));
            memcpy(&file.modified, &mcDir[i]._Modify, sizeof(sceMcStDateTime));
            strncpy(file.name, mcDir[i].EntryName, 32);         
            
            snprintf(filePath, 100, "%s/%s", save->path, file.name);
            mcFile = fopen(filePath, "rb");
            data = malloc(file.length);
            fread(data, 1, file.length, mcFile);
            fclose(mcFile);
            
            fwrite(&file, 1, 512, psuFile);
            fwrite(data, 1, file.length, psuFile);
            free(data);
            numFiles++;
            
            padding = 1024 - (file.length % 1024);
            if(padding < 1024)
            {
                for(j = 0; j < padding; j++)
                    fputc(0, psuFile);
            }
        }
    }
    
    fseek(psuFile, 0, SEEK_SET);
    dir.length = numFiles + 2;
    strncpy(dir.name, strstr(save->path, ":") + 1, 32);
    fwrite(&dir, 1, 512, psuFile); // root directory
    dir.length = 0;
    strncpy(dir.name, ".", 32);
    fwrite(&dir, 1, 512, psuFile); // .
    strncpy(dir.name, "..", 32);
    fwrite(&dir, 1, 512, psuFile); // ..
    fclose(psuFile);
    
    return 1;
}