Exemple #1
0
        // Save mosaic data.
        internal void SaveMosaicCacheFile()
        {
            if (this.threadController != null)
            {
                this.threadController.ReportThreadStarted(this, "Saving Tiles");
            }

            string tempFilePath = Path.GetTempFileName();

            try
            {
                this.oZipStream = new ZipOutputStream(System.IO.File.Create(tempFilePath));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }

            this.oZipStream.SetLevel(2); // 9 = maximum compression level

            ZipEntry oZipEntry = new ZipEntry("info.txt");

            this.oZipStream.PutNextEntry(oZipEntry);

            StreamWriter sw = new StreamWriter(oZipStream);

            TileSaver.SaveMosaicHeader(MosaicWindow.MosaicInfo, sw);

            ThumbnailMapCollection mapCollection = new ThumbnailMapCollection(MosaicWindow.MosaicInfo.Items[0].Thumbnail.Width,
                                                                              MosaicWindow.MosaicInfo.Items[0].Thumbnail.Height);

            mapCollection.MapFilled += new ThumbnailMapCollectionEventHandler(OnMapFilled);

            int count        = 1;
            int requiredMaps = (MosaicWindow.MosaicInfo.Items.Count / ThumbnailMap.MaxSize) + 1;

            foreach (Tile tile in MosaicWindow.MosaicInfo.Items) // For each file, generate a zipentry
            {
                if (this.threadController.ThreadAborted)
                {
                    return;
                }

                mapCollection.AddThumbnail(tile);

                if (this.threadController != null)
                {
                    threadController.ReportThreadPercentage(this, "Creating Tile Maps",
                                                            count++, MosaicWindow.MosaicInfo.Items.Count);
                }
            }

            // Final map may not get completly filled
            // if not then save it here

            if (mapCollection.Maps.Count <= requiredMaps)
            {
                ThumbnailMapCollectionEventArgs thumbnailEventArgs
                    = new ThumbnailMapCollectionEventArgs(mapCollection.Last);

                OnMapFilled(mapCollection, thumbnailEventArgs);
            }

            mapCollection.Dispose();
            oZipStream.Finish();
            oZipStream.Dispose();
            oZipStream.Close();

            try
            {
                File.Delete(MosaicWindow.MosaicInfo.TileReader.GetCacheFilePath());
                File.Copy(tempFilePath, MosaicWindow.MosaicInfo.TileReader.GetCacheFilePath());
            }
            catch (Exception)
            {
            }

            //File.SetAttributes(this.filePath, FileAttributes.Hidden);

            if (this.threadController != null)
            {
                this.threadController.ReportThreadCompleted(this, "Cache Saved", false);
            }

            GC.Collect();
        }