void FreeGallery(WebGalleryBase gallery)
 {
     if (gallery == null)
     {
         return;
     }
     FolderHelper.RemoveFolder(gallery.TargetFolder);
 }
        public static void PrepareEngineStructure(WebGalleryBase gallery)
        {
            if (!Directory.Exists(gallery.TargetFolder))
            {
                return;
            }
            string name = WebGalleryBase.GalleriesFolder + gallery.ZipName;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) {
                ZipHelper.Decompress(stream, gallery.TargetFolder);
            }
        }
        public static void PatchItemsFile(WebGalleryBase gallery, List <DmFile> files)
        {
            string htmlFile = Path.Combine(gallery.TargetFolder, gallery.ItemsFile);

            if (!File.Exists(htmlFile))
            {
                throw new InvalidOperationException();
            }
            if (files == null || files.Count < 1)
            {
                return;
            }

            string        html      = File.ReadAllText(htmlFile);
            int           insertInd = html.IndexOf(WebGalleryBase.inputPoint);
            StringBuilder sb        = new StringBuilder(html);

            sb.Remove(insertInd, WebGalleryBase.inputPoint.Length);

            foreach (DmFile file in files)
            {
                //TO DO
                string pathFull     = gallery.ImagesFolderFullPath + file.FileName;
                string pathRelative = Path.Combine(gallery.ImagesFolder, file.FileName);
                ThumbHelper.GetThumbnailImage(file).Save(pathFull, System.Drawing.Imaging.ImageFormat.Jpeg);

                //string pathFullThumb = gallery.ThumbsFolderFullPath + file.FileName;
                //string pathRelativeThumb = Path.Combine(gallery.ThumbsFolder, file.FileName);
                //ThumbHelper.GetIconImage(file).Save(pathFullThumb, System.Drawing.Imaging.ImageFormat.Jpeg);

                pathRelative = pathRelative.Replace(@"\", "/");
                //pathRelativeThumb = pathRelativeThumb.Replace(@"\", "/");
                string newString = gallery.GenerateItemTag(pathRelative, null);
                newString += Environment.NewLine;
                sb.Insert(insertInd, newString);
                insertInd += newString.Length;
            }
            File.WriteAllText(htmlFile, sb.ToString());
        }
 void InitGallery(WebGalleryBase gallery, string targetFolder)
 {
     gallery.TargetFolder = targetFolder;
     WebGalleryHelper.PrepareEngineStructure(gallery);
     WebGalleryHelper.PatchItemsFile(gallery, Files);
 }
 void InitGallery(WebGalleryBase newGallery)
 {
     InitGallery(newGallery, FolderHelper.CreateTempFolder());
 }
 void OnGalleryChanged(WebGalleryBase newGallery, WebGalleryBase oldGallery)
 {
     FreeGallery(oldGallery);
     InitGallery(newGallery);
     webBrowser1.Navigate(newGallery.IndexPageFullPath);
 }