Exemplo n.º 1
0
bool ProjectFile::SaveProject()
{
	if (OpenFileWrite())
		if (SaveFile())
			return CloseFile();
	return false;
}
Exemplo n.º 2
0
/**
 * @brief Creates a project directory (and a project file within that directory) in the
 * parent directory
 *
 * Creates a project directory (and a project file within that directory) in the
 * parent directory. The newly created project file is opened and all ProjectFile
 * access functions become available.
 *
 * If a project file is already open, we first prompt the user to either save,
 * discard changes, or cancel creating a new project.
 *
 * @param parentDirectory The directory in which to create the project directory
 * @param projectName The name to give both the project directory and the project file
 */
bool ProjectFile::CreateProjectFile(QString parentDirectory, QString projectName)
{
	if (!ProjectIsOpen() || WarnProjectAlreadyOpen())
	{
		/* Move into the project directory */
		/* If the directory doesn't exist, try to create it */
		projectDirectory = QDir(parentDirectory);
		if (!projectDirectory.cd(projectName))
		{
			if (!projectDirectory.mkdir(projectName))
			{
				WarnFileError("Unable to create project directory");
				return false;
			}
			else if (!projectDirectory.cd(projectName))
			{
				WarnFileError("Unable to access the project directory");
				return false;
			}
		}

		/* Make sure there isn't a project file in the directory already */
		projectDirectory.setNameFilters(QStringList("*.spf"));
		if (!projectDirectory.entryList().isEmpty())
		{
			WarnFileError(QString("A project file already exists at ").append(parentDirectory+projectName));
			return false;
		}

		/* Create the file */
		SetProjectFile(projectDirectory.absolutePath() + QDir::separator() + projectName + ".spf");
		if (OpenFileWrite())
		{
			/* Create an empty project */
			CreateEmptyProject();

			/* Save the project file */
			SaveFile();

			/* Close the project file */
			CloseFile();

			return true;
		}
	}
	return false;
}
Exemplo n.º 3
0
static void SavePNG(uint8_t* buffer, int width, int height)
{
    wchar_t* fileName = xmalloc(32768 * sizeof(wchar_t));

    GenerateFileName(fileName, 32768);

    if (ShowSaveDialog(fileName, 32768))
    {
        FILE* file = OpenFileWrite(fileName);

        if (!file)
            Fatal(L"Couldn't write file.");

        if (!WritePNG(file, buffer, width, height))
            Fatal(L"Couldn't write PNG.");

        fclose(file);
    }

    free(fileName);
}