public static bool Save(Form formMain) { // save main window size/position settings.window.left = formMain.Left; settings.window.top = formMain.Top; settings.window.height = formMain.Height; settings.window.width = formMain.Width; // save maximized state settings.window.maximized = formMain.WindowState == FormWindowState.Maximized ? true : false; // set modified, version settings.about = GetConfigSettingsAbout(); string configFile = MyFile.EnsureDataFile("settings", settings.exportExt, "config"); if (configFile == null) { return(false); } MyLog.RotateFiles(configFile); // save new settings MySerialize.ToFile(settings.exportFormat, configFile, settings); return(true); }
public static bool Load() { bool ret = true; string syncFile = MyFile.EnsureDataFile("sync", Config.settings.exportExt, "sync"); if (File.Exists(syncFile)) { // load settings syncSettings = (SyncSettings)MyDeserialize.FromFile(Config.settings.exportFormat, syncFile, syncSettings); if (syncSettings.guid == null || syncSettings.about == null) { syncSettings.Initialize(); } } else { syncSettings.Initialize(); } return(ret); }
private void tabControlSettings_SelectedIndexChanged(object sender, EventArgs e) { if (tabControlSettings.SelectedIndex == 1) { // meta data tab } else if (tabControlSettings.SelectedIndex == 2) { // external tab string ffprobeExe = MyFile.EnsureDataFile("ffprobe", "exe", @"libs/ffmpeg/bin"); if (!File.Exists(ffprobeExe)) { labelFFProbeStatus.Text = "Not Found"; labelFFProbeStatus.ForeColor = Color.OrangeRed; } else { labelFFProbeStatus.Text = "Available"; labelFFProbeStatus.ForeColor = Color.ForestGreen; } } else if (tabControlSettings.SelectedIndex == 3) { SetGalleryCacheSize(); } }
public static bool SaveVideoInfo(VideoInfo videoInfo) { // MyLog.Add("SaveVideoInfo"); listVideoInfos[videoInfo.index] = videoInfo; UpdateVideo updateVideo = new UpdateVideo(); updateVideo.UpdateMVE(videoInfo); updateVideo.UpdateXBMC(videoInfo); updateVideo.UpdateMB(videoInfo); // delete prior statsfile, if any, so stats will be re-calced string statsFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (statsFile != null) { MyFile.DeleteFile(statsFile); } return(true); }
protected bool LoadSelectedFilter() { if (comboBoxFilters.Items.Count == 0) { return(false); } if (subFormFilterForm == null) { return(false); } string filterName = comboBoxFilters.Text; if (filterName.Length == 0) { return(false); } if (filterName == "<_reset_>") { subFormFilterForm.ResetForm(); return(true); } if (filterName == "<filter when closed>") { filterName = "filter when closed"; } else if (filterName == "<last saved filter>") { filterName = "last saved filter"; } FilterInfo filterInfo = new FilterInfo(); // subFormFilterForm.GetFilterForm(); string dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", filterName); // MessageBox.Show(dataFile); if (File.Exists(dataFile)) { // load filter preset filterInfo = (FilterInfo)MyDeserialize.FromFile(Config.settings.exportFormat, dataFile, filterInfo); if (filterInfo == null) { MessageBox.Show("Unable to load Filter [" + filterName + "]"); return(false); } subFormFilterForm.ResetForm(); subFormFilterForm.SetFilterForm(filterInfo); MyLog.Add("Loaded Filter Preset " + dataFile.Replace(MyFile.exeDirectory, "")); return(true); } return(false); }
protected void BackgroundWorkerScanSource_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // delete prior statsfile, if any, so stats will be re-calced string statsFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (statsFile != null) { MyFile.DeleteFile(statsFile); } VideoInfos_RunWorkerCompleted("scan", "Scanning done", sender, e); }
public static bool Save() { if (listVideoInfos == null) { return(false); } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); MyLog.Add("Saving VideoItems -->"); foreach (ConfigSettings.Source settingsSource in Config.settings.sources) { string dataFile = MyFile.EnsureDataFile("videos", Config.settings.exportExt, "data", settingsSource.alias); if (dataFile == null) { continue; } List <VideoInfo> saveVideoInfos = new List <VideoInfo>(listVideoInfos.Count()); saveVideoInfos = listVideoInfos.Where(x => x.sourceAlias == settingsSource.alias && x.videoItem != null && x.videoItem.title != null).OrderBy(x => x.videoItem.title).ToList(); if (saveVideoInfos == null) { continue; } int nbrVideoInfos = saveVideoInfos.Count(); if (nbrVideoInfos == 0) { continue; } MyLog.RotateFiles(dataFile); MySerialize.ToFile(Config.settings.exportFormat, dataFile, saveVideoInfos); FileInfo fileInfo = MyFile.FileInfo(dataFile); string toFile = "to " + dataFile.Replace(MyFile.exeDirectory, ""); if (fileInfo != null) { toFile += " " + MyFile.FormatSize(fileInfo.Length); } MyLog.Add("Saved " + nbrVideoInfos + " VideoItems " + toFile); } stopWatch.Stop(); MyLog.AddElapsed("<-- in ", stopWatch.Elapsed); return(true); }
public static bool Load() { bool ret = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // MyLog.Add("Loading VideoItemStats"); string dataFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (dataFile == null) { return(false); } // keep a backup of settings if (File.Exists(dataFile)) { videoInfoStats = new VideoInfoStats(); videoInfoStats = (VideoInfoStats)MyDeserialize.FromFile(Config.settings.exportFormat, dataFile, videoInfoStats); string fromFIle = "from " + dataFile.Replace(MyFile.exeDirectory, ""); FileInfo fileInfo = MyFile.FileInfo(dataFile); if (fileInfo != null) { fromFIle += " " + MyFile.FormatSize(fileInfo.Length); } MyLog.Add("Loaded VideoInfoStats " + fromFIle); if (videoInfoStats != null && videoInfoStats.year != null && videoInfoStats.year.Count() > 0) { ret = true; } } else { // MyLog.Add("No VideoInfoStats to load "); } stopWatch.Stop(); if (ret) { MyLog.AddElapsed(stopWatch.Elapsed); } return(ret); }
public static bool Save() { string dataFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (dataFile == null) { return(false); } MyLog.RotateFiles(dataFile); MySerialize.ToFile(Config.settings.exportFormat, dataFile, videoInfoStats); return(true); }
public static bool Save() { string syncFile = MyFile.EnsureDataFile("sync", Config.settings.exportExt, "sync"); if (syncFile == null) { return(false); } MyLog.RotateFiles(syncFile); // save new settings MySerialize.ToFile(Config.settings.exportFormat, syncFile, syncSettings); return(true); }
public bool DeleteFilter(string preset) { bool ret = false; if (MessageBox.Show("Delete Filter Preset [" + preset + "]", "Filter Preset", MessageBoxButtons.YesNo) == DialogResult.Yes) { string dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", preset); // MessageBox.Show(dataFile); if (MyFile.DeleteFile(dataFile)) { // MessageBox.Show("Deleted Filter Preset [" + preset + "]"); comboBoxFilters.Items.Remove(comboBoxFilters.SelectedItem); LoadFilters(); // subFormFilterForm.ResetForm(); ret = true; } else { MessageBox.Show("Error deleting Filter Preset [" + preset + "]"); } } return(ret); }
public bool LoadFilters() { // also ensures directory filter exists string dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters"); IEnumerable <string> files = MyFile.EnumerateFiles("filters", "Filter_*." + Config.settings.exportExt); comboBoxFilters.SuspendLayout(); comboBoxFilters.Items.Clear(); comboBoxFilters.Items.Add("<_reset_>"); comboBoxFilters.Items.Add("<filter when closed>"); comboBoxFilters.Items.Add("<last saved filter>"); comboBoxFilters.SelectedIndex = 0; if (files.Count() > 0) { Regex regexIgnoreBackups = new Regex(@"\.[0-9]\." + Config.settings.exportExt); foreach (string file in files) { if (regexIgnoreBackups.IsMatch(file)) { continue; } string filterName = file.Replace(@"filters\", ""); filterName = filterName.Replace(@"." + Config.settings.exportExt, ""); filterName = filterName.Replace(@"Filter_", ""); if (filterName == "_reset_" || filterName == "filter when closed" || filterName == "last saved filter") { continue; } comboBoxFilters.Items.Add(filterName); } } comboBoxFilters.ResumeLayout(); return(true); }
/// <summary> /// log message to the log file /// always log exceptions e.ToString() so can debug/fix /// </summary> /// <param name="message"></param> public static void Add(string message) { if (logFile == null) { logFile = MyFile.EnsureDataFile("mve", "log", "logs"); } try { string privateMemorySize; using (Process currentProcess = Process.GetCurrentProcess()) { privateMemorySize = MyFile.FormatSize(currentProcess.PrivateMemorySize64); } using (StreamWriter streamWriter = File.AppendText(logFile)) { streamWriter.WriteLine("{0} | {1} | {2} | ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ff"), privateMemorySize, message); } } catch (Exception e) { if (Application.OpenForms.Count > 0) { MessageBox.Show("Unable to write to log [" + e.Message + "]"); } } // check if should rotate logs; but only check occasionaly, to reduce io checks Random random = new Random(); if (random.Next(1, 100) < 20) { RotateLogs(logFile); } }
public bool SaveFilter(string filterName) { if (filterName.Length == 0) { return(false); } string dataFile; if (filterName == "<_reset_>") { MessageBox.Show("Cannot Save filter"); subFormFilterForm.ResetForm(); return(false); } else if (filterName == "<filter when closed>") { dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", "filter when closed"); if (dataFile == null) { return(false); } } else if (filterName == "<last saved filter>") { MessageBox.Show("Cannot Save filter.\nThis Filter will be automaticlly be saved when you Save another Filter."); return(false); } else { filterName = MyFile.SafeFileName(filterName); dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", filterName); if (dataFile == null) { return(false); } allow_comboBoxPreset_SelectedIndexChanged = false; comboBoxFilters.Text = filterName; allow_comboBoxPreset_SelectedIndexChanged = true; } FilterInfo filterInfo = subFormFilterForm.GetFilterForm(); MyLog.RotateFiles(dataFile); filterInfo.about = Config.GetConfigSettingsAbout(); filterInfo.name = filterName; if (filterInfo.description == null) { filterInfo.description = ""; } MySerialize.ToFile(Config.settings.exportFormat, dataFile, filterInfo); MyLog.Add("Saved Filter Preset " + dataFile.Replace(MyFile.exeDirectory, "")); // make a copy of last saved filter if (filterName != "<last saved filter>" && filterName != "<filter when closed>") { dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", "last saved filter"); if (dataFile == null) { return(false); } MyLog.RotateFiles(dataFile); MySerialize.ToFile(Config.settings.exportFormat, dataFile, filterInfo); MyLog.Add("Saved Filter Preset " + dataFile.Replace(MyFile.exeDirectory, "")); } return(true); }
public static bool Load() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); MyLog.Add("Loading VideoItems -->"); int nbrVideoInfos; FileInfo fileInfo; CreateList(); foreach (ConfigSettings.Source source in Config.settings.sources) { string dataFile = MyFile.EnsureDataFile("videos", Config.settings.exportExt, "data", source.alias); if (dataFile == null) { continue; } // keep a backup of settings if (File.Exists(dataFile)) { fileInfo = MyFile.FileInfo(dataFile); List <VideoInfo> loadVideoInfos = (List <VideoInfo>)MyDeserialize.FromFile(Config.settings.exportFormat, dataFile, listVideoInfos); if (loadVideoInfos == null) { MyLog.Add("Unable to load VideoInfos from " + dataFile); continue; } AddItems(loadVideoInfos); string fromFile = "from " + dataFile.Replace(MyFile.exeDirectory, ""); if (fileInfo != null) { fromFile += " " + MyFile.FormatSize(fileInfo.Length); } if (loadVideoInfos == null) { nbrVideoInfos = 0; } else { nbrVideoInfos = loadVideoInfos.Count(); } MyLog.Add("Loaded " + nbrVideoInfos + " VideoItems " + fromFile); } } EnsureVideoInfos(); stopWatch.Stop(); if (listVideoInfos == null) { nbrVideoInfos = 0; } else { nbrVideoInfos = listVideoInfos.Count(); } MyLog.AddElapsed("<-- in ", stopWatch.Elapsed); bool loaded = nbrVideoInfos > 0 ? true : false; return(loaded); }
private string RunFFprobe(string videoFilePath) { Process process = null; string encoding = null; string error = null; if (!File.Exists(videoFilePath)) { // MyLog.Add("Video not found " + fileInfo.FullName); return(encoding); } string ffprobeExe = MyFile.EnsureDataFile("ffprobe", "exe", @"libs/ffmpeg/bin"); if (!File.Exists(ffprobeExe)) { // MyLog.Add("FFMPEG: not found " + ffprobeExe); return(encoding); } try { encodingFFProbeError = ""; encodingFFProbeOutput = ""; string workingDirectory = MyFile.exeDirectory; // MyFile.exeDirectory + "/temp"; // MyFile.exeDirectory; string arguments = string.Format("-v warning -show_error -show_format -show_streams -print_format xml \"{0}\"", videoFilePath); // MyLog.Add("RunFFprobe: Start " + videoItemFile.FullName + ": \"" + ffprobeExe + "\" " + arguments); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = ffprobeExe; startInfo.Arguments = arguments; startInfo.CreateNoWindow = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.WorkingDirectory = workingDirectory; process = new Process(); process.StartInfo = startInfo; process.OutputDataReceived += RunFFprobe_Output; process.ErrorDataReceived += RunFFprobe_Error; // use this order of events to avoid deadlock // http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx // http://msdn.microsoft.com/en-us/library/system.diagnostics.process.outputdatareceived%28v=vs.110%29.aspx process.Start(); // StreamReader streamReaderError = process.StandardError; // encoding = process.StandardError.ReadToEnd(); // process.BeginOutputReadLine(); // encoding = process.StandardOutput.ReadToEnd(); // works, simplier process.BeginOutputReadLine(); process.BeginErrorReadLine(); // so far doesnt seem to catch errors process.WaitForExit(5000); if (!String.IsNullOrEmpty(encodingFFProbeError)) { MyLog.Add("RunFFprobe: Error on " + videoFilePath + " : " + encodingFFProbeError); } encoding = encodingFFProbeOutput.Trim(); // clean up temp folder occasionaly Random random = new Random(); int chance = random.Next(0, 100); if (false && chance < 25) { string[] ffprobeLogs = Directory.GetFiles(workingDirectory, "ffprobe*.log"); foreach (string ffprobeLog in ffprobeLogs) { File.Delete(ffprobeLog); } } } catch (Exception e) { MyLog.Add("RunFFprobe: " + e.ToString()); } // MyLog.Add("RunFFprobe: Finish " + videoItemFile.FullName + ": " + encoding); try { string status; if (process.ExitCode == 0) { status = "Success"; } else { status = "Error"; } MyLog.Add("RunFFprobe: " + status + " code:" + process.ExitCode.ToString() + " probed in:" + process.TotalProcessorTime.Milliseconds.ToString() + "ms"); } catch (Exception) { } if (error != null) { MyLog.Add(error); } if (process != null) { process.Close(); } // meh, throttle some Thread.Sleep(10); return(encoding); }
public static GalleryImageThumbnailInfo GetCachedThumbnail(VideoInfo videoInfo) { GalleryImageThumbnailInfo galleryImageThumbnailInfo = new GalleryImageThumbnailInfo(); galleryImageThumbnailInfo.fromCache = false; galleryImageThumbnailInfo.createdCache = false; galleryImageThumbnailInfo.thumbnail = null; Image thumbnail = null; string cachedThumbnailFullName = MyFile.EnsureDataFile("poster_" + videoInfo.hash, "jpg", @"cache\gallery"); if (Config.settings.gallery.cachePosterThumbnails && File.Exists(cachedThumbnailFullName)) { // use file stream so files not locked FileStream fileStream = new FileStream(cachedThumbnailFullName, FileMode.Open, FileAccess.Read); thumbnail = Image.FromStream(fileStream); fileStream.Close(); // thumbnail = Image.FromFile(cachedThumbnailFile); // locks file galleryImageThumbnailInfo.fromCache = true; } else if (videoInfo.files.poster == null) { thumbnail = null; } else { VideoItemFile videoItemFile = videoInfo.files.poster; string posterFullName = videoInfo.GetFullName(videoItemFile); // skip images smaller than y or larger than x if (videoItemFile.Length < 100) { MyLog.Add("Get Thumbnail: Skipping " + posterFullName + " " + MyFile.FormatSize(videoItemFile.Length)); thumbnail = null; } if (videoItemFile.Length > 5 * 1048576) { MyLog.Add("Get Thumbnail: Skipping " + posterFullName + " " + MyFile.FormatSize(videoItemFile.Length)); thumbnail = null; } try { if (!File.Exists(posterFullName)) { thumbnail = null; } else { // size of thumbails .. TODO make a config setting thumbnail = MyImage.GetThumbnail(posterFullName, 165, 250, Color.Black); if (Config.settings.gallery.cachePosterThumbnails && thumbnail != null) { // clone image so files not locked if (MyImage.SaveJpgImage((Image)thumbnail.Clone(), cachedThumbnailFullName)) { galleryImageThumbnailInfo.createdCache = true; } } } } catch (OutOfMemoryException) { // Image.FromFile will throw this if file is invalid/corrupted; Don't ask me why MyLog.Add("Invalid Image; Unable to read " + posterFullName + " " + MyFile.FormatSize(videoItemFile.Length)); thumbnail = null; } catch (Exception ei) { MyLog.Add(ei.ToString()); thumbnail = null; } } galleryImageThumbnailInfo.thumbnail = thumbnail; return(galleryImageThumbnailInfo); }
public static bool Load(Form mainForm) { bool ret = true; // app non configurable, so far, settings settings.exportFormat = "json"; settings.exportExt = "json"; // chicken egg string configFile = MyFile.EnsureDataFile("settings", settings.exportExt, "config"); bool bLoadDefaults = false; if (File.Exists(configFile)) { // load settings settings = (ConfigSettings)MyDeserialize.FromFile(settings.exportFormat, configFile, settings); } else { bLoadDefaults = true; ret = false; } if (settings == null || settings.sources == null || settings.window == null || settings.gallery == null) { bLoadDefaults = true; ret = false; } else { if (settings.window.left > 0 && settings.window.top > 0 && settings.window.height > 0 && settings.window.width > 0) { // restore position/size mainForm.Left = settings.window.left; mainForm.Top = settings.window.top; mainForm.Height = settings.window.height; mainForm.Width = settings.window.width; } if (settings.window.maximized == true) { // restore to maximized state mainForm.WindowState = FormWindowState.Maximized; } } // could not load settings, so set minimal defaults if (bLoadDefaults) { // meh, check all for defaults } // ensure other settings exist, else default if (settings == null) { settings = new ConfigSettings(); bLoadDefaults = true; } if (settings.sources == null) { settings.sources = new List <ConfigSettings.Source>();; } if (settings.gallery == null) { settings.gallery = new ConfigSettings.Gallery(); bLoadDefaults = true; } if (settings.gallery.backColor == Color.Empty) { settings.gallery.backColor = Color.DarkSlateBlue; } if (bLoadDefaults) { settings.gallery.enable = false; settings.gallery.cachePosterThumbnails = true; } // app non configurable, so far, settings settings.exportFormat = "json"; settings.exportExt = "json"; return(ret); }