public void SaveInfo() { if (FileInfo == null) { return; } try { PhotoUtils.CreateFolder(InfoFile); var json = JsonConvert.SerializeObject(FileInfo); File.WriteAllText(InfoFile, json); //FileInfo.ValidateValues(); //XmlSerializer serializer = new XmlSerializer(typeof(FileInfo)); //// Create a FileStream to write with. //System.Text.Encoding code = Encoding.GetEncoding("UTF-8"); //StreamWriter writer = new StreamWriter(InfoFile, false, code); //// Serialize the object, and close the TextWriter //serializer.Serialize(writer, FileInfo); //writer.Close(); } catch (Exception e) { Log.Error("Unable to save session info file", e); } }
public void SaveInfo() { if (FileInfo == null) { return; } try { PhotoUtils.CreateFolder(InfoFile); FileInfo.ValidateValues(); XmlSerializer serializer = new XmlSerializer(typeof(FileInfo)); // Create a FileStream to write with. System.Text.Encoding code = Encoding.GetEncoding("UTF-8"); StreamWriter writer = new StreamWriter(InfoFile, false, code); // Serialize the object, and close the TextWriter serializer.Serialize(writer, FileInfo); writer.Close(); } catch (Exception) { Log.Error("Unable to save session branding file"); } }
public void GenerateCache(FileItem fileItem) { bool deleteFile = false; if (fileItem == null) { return; } if (!File.Exists(fileItem.FileName)) { return; } if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile)) { return; } if (fileItem.Loading) { return; } fileItem.Loading = true; PhotoUtils.WaitForFile(fileItem.FileName); string filename = fileItem.FileName; if (fileItem.IsMovie) { try { string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe"); if (File.Exists(ffmpeg_exe)) { string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName), Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg"); PhotoUtils.RunAndWait(ffmpeg_exe, String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"", fileItem.FileName, thumb)); if (File.Exists(thumb)) { deleteFile = true; filename = thumb; } } } catch (Exception exception) { Log.Error("Error get video thumb", exception); } } if (fileItem.IsRaw) { try { string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe"); if (File.Exists(dcraw_exe)) { string thumb = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg"); PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e -O \"{0}\" \"{1}\"", thumb, fileItem.FileName)); if (File.Exists(thumb)) { deleteFile = true; filename = thumb; } } } catch (Exception exception) { Log.Error("Error get dcraw thumb", exception); } } GetMetadata(fileItem); try { using (MagickImage image = new MagickImage(filename)) { fileItem.FileInfo.SetSize(image.Width, image.Height); double dw = (double)LargeThumbSize / image.Width; image.FilterType = FilterType.Box; image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw)); if (!ServiceProvider.Settings.DisableHardwareAccelerationNew) { image.UnsharpMask(1, 1, 0.5, 0.1); } PhotoUtils.CreateFolder(fileItem.LargeThumb); image.Write(fileItem.LargeThumb); fileItem.IsLoaded = true; fileItem.Loading = false; dw = (double)SmallThumbSize / image.Width; image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw)); if (!ServiceProvider.Settings.DisableHardwareAccelerationNew) { image.UnsharpMask(1, 1, 0.5, 0.1); } PhotoUtils.CreateFolder(fileItem.SmallThumb); image.Write(fileItem.SmallThumb); fileItem.Thumbnail = LoadImage(fileItem.SmallThumb); } fileItem.SaveInfo(); SetImageInfo(fileItem); if (deleteFile) { File.Delete(filename); } OnMetaDataUpdated(fileItem); } catch (Exception exception) { Log.Error("Error generating cache " + fileItem.FileName, exception); } fileItem.Loading = false; }