/// <summary>
        /// Load and add project from file.
        /// </summary>
        /// <returns>Returns the new project.</returns>
        /// <exception cref='DuplicateException'>Tried to add duplicate file to collection.</exception>
        public PPProject LoadProject(string fullFileName)
        {
            PPProject project = LoadProject_Internal(fullFileName);

            EditedSinceLastSave = true;
            return(project);
        }
Esempio n. 2
0
 public static void LoadProject(string zipFilename, PPProject project)
 {
     using (Package package = Package.Open(zipFilename, FileMode.Open))
     {
         if (!package.PartExists(URI_PART_GREYSCALE))
         {
             throw new FileFormatException("Project zip file does not include greyscale image.");
         }
         if (!package.PartExists(URI_PART_COLOR))
         {
             throw new FileFormatException("Project zip file does not include color image.");
         }
         project.GreyscaleBitmap = package.GetPart(URI_PART_GREYSCALE).GetStream().StreamToByteArray().ByteArrayToBitmap();
         project.ColorBitmap     = package.GetPart(URI_PART_COLOR).GetStream().StreamToByteArray().ByteArrayToBitmap();
         project.ColorPalette    = null;
         if (package.PartExists(URI_PART_PALETTE))
         {
             string[]  paletteLines = package.GetPart(URI_PART_PALETTE).GetStream().StreamToByteArray().ByteArrayToText();
             FormatGPL gpl          = new FormatGPL(paletteLines);
             project.ColorPalette = gpl.ColorPalette;
         }
         project.Config = null;
         if (package.PartExists(URI_PART_CONFIG))
         {
             string[] configLines = package.GetPart(URI_PART_CONFIG).GetStream().StreamToByteArray().ByteArrayToText();
             project.Config = new PPConfig(configLines);
         }
     }
 }
Esempio n. 3
0
        public static PPProject LoadProject(string zipFilename)
        {
            PPProject project = new PPProject();

            LoadProject(zipFilename, project);
            return(project);
        }
Esempio n. 4
0
        /// <summary>
        /// Create new project with image loaded.
        /// </summary>
        public static PPProject FromImage(string fullFileName)
        {
            PPProject project = new PPProject();

            project.LoadImage(fullFileName);
            return(project);
        }
Esempio n. 5
0
 /// <summary>
 /// Returns true if these projects are from the same file.
 /// </summary>
 public bool FromSameFile(PPProject other)
 {
     if (!String.IsNullOrEmpty(this.LoadedFromFileName))
     {
         return(this.LoadedFromFileName == other.LoadedFromFileName);
     }
     return(false);
 }
        /// <summary>
        /// Add project to collection.
        /// </summary>
        /// <exception cref='DuplicateException'>Tried to add duplicate file to collection.</exception>
        private void AddProject(PPProject project)
        {
            if (projects.Any(p => p.FromSameFile(project)))
            {
                throw new DuplicateException("File is already in the collection.");
            }

            projects.Add(project);
        }
        private PPProject LoadProject_Internal(string fullFileName)
        {
            if (String.IsNullOrEmpty(fullFileName))
            {
                throw new FileNotFoundException("Cannot load from empty file name.");
            }
            PPProject project = null;

            if (Path.GetExtension(fullFileName) == PPProject.PROJECT_EXTENSION)
            {
                project = PPProject.FromProject(fullFileName);
            }
            else
            {
                project = PPProject.FromImage(fullFileName);
            }
            AddProject(project);
            return(project);
        }
Esempio n. 8
0
 /// <summary>
 /// Saved a zipped Perpetual Paint Project file.
 /// </summary>
 /// <remarks>
 /// Creates or overwrites <paramref name='zipFilename'/>.
 ///
 /// Handles:
 /// - include entire palette
 /// - include filename of palette (in config)
 /// - include no palette information
 /// </remarks>
 public static void ZipProject(string zipFilename, PPProject project)
 {
     byte[] zippedBytes;
     using (MemoryStream zipStream = new MemoryStream())
     {
         using (Package package = Package.Open(zipStream, FileMode.Create))
         {
             PackagePart greyscaleDocument = package.CreatePart(URI_PART_GREYSCALE, "");
             using (MemoryStream dataStream = new MemoryStream(project.GreyscaleBitmap.ToByteArray()))
             {
                 greyscaleDocument.GetStream().WriteAll(dataStream);
             }
             PackagePart colorDocument = package.CreatePart(URI_PART_COLOR, "");
             using (MemoryStream dataStream = new MemoryStream(project.ColorBitmap.ToByteArray()))
             {
                 colorDocument.GetStream().WriteAll(dataStream);
             }
             if (project.ColorPalette != null)
             {
                 PackagePart paletteDocument = package.CreatePart(URI_PART_PALETTE, "");
                 using (MemoryStream dataStream = new MemoryStream(FormatGPL.ToTextFormat(project.ColorPalette).ToByteArray()))
                 {
                     paletteDocument.GetStream().WriteAll(dataStream);
                 }
             }
             if (project.Config != null)
             {
                 PackagePart configDocument = package.CreatePart(URI_PART_CONFIG, "");
                 using (MemoryStream dataStream = new MemoryStream(project.Config.ToTextFormat().ToByteArray()))
                 {
                     configDocument.GetStream().WriteAll(dataStream);
                 }
             }
         }
         zippedBytes = zipStream.ToArray();
     }
     File.WriteAllBytes(zipFilename, zippedBytes);
 }
Esempio n. 9
0
 public ProjectEventArgs(PPProject project)
 {
     Project = project;
 }