private void ClearRecordingCache() { try { var path = Path.Combine(UserSettings.All.TemporaryFolderResolved, "ScreenToGif", "Recording"); if (!Directory.Exists(path)) { return; } var list = Directory.GetDirectories(path).Select(x => new DirectoryInfo(x)) .Where(w => (DateTime.Now - w.CreationTime).TotalDays > (UserSettings.All.AutomaticCleanUpDays > 0 ? UserSettings.All.AutomaticCleanUpDays : 5)).ToList(); //var list = Directory.GetDirectories(path).Select(x => new DirectoryInfo(x)); foreach (var folder in list) { if (MutexList.IsInUse(folder.Name)) { continue; } Directory.Delete(folder.FullName, true); } } catch (Exception ex) { LogWriter.Log(ex, "Automatic clean up - Recordings"); } }
public void CreateMutex() { //TODO: Validate the possibility of openning this project. //I need to make sure that i'll release the mutexes. MutexList.Add(RelativePath); }
private void App_Exit(object sender, ExitEventArgs e) { try { MutexList.RemoveAll(); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to remove all mutexes of the opened projects."); } try { NotifyIcon?.Dispose(); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to dispose the system tray icon."); } try { EncodingManager.StopAllEncodings(); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to cancel all encodings."); } try { UserSettings.Save(); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to save the user settings."); } try { if (_mutex != null && _accepted) { _mutex.ReleaseMutex(); _accepted = false; } } catch (Exception ex) { LogWriter.Log(ex, "Impossible to release the single instance mutex."); } try { HotKeyCollection.Default.Dispose(); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to dispose the hotkeys."); } }
private void App_OnExit(object sender, ExitEventArgs e) { //TODO: Use a try catch for each one. MutexList.RemoveAll(); UserSettings.Save(); HotKeyCollection.Default.Dispose(); }
public ProjectInfo(Int32Rect frameSize) { //Check if the parameter exists. if (string.IsNullOrWhiteSpace(UserSettings.All.TemporaryFolder)) { UserSettings.All.TemporaryFolder = Path.GetTempPath(); } RelativePath = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + Path.DirectorySeparatorChar; FrameSize = frameSize; Directory.CreateDirectory(FullPathOfProject); MutexList.Add(RelativePath); }
private async void ClearTempButton_Click(object sender, RoutedEventArgs e) { ClearTempButton.IsEnabled = false; try { var path = Path.Combine(UserSettings.All.TemporaryFolder, "ScreenToGif", "Recording"); if (!Directory.Exists(path)) { _folderList.Clear(); return; } _folderList = await Task.Factory.StartNew(() => Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly).Select(x => new DirectoryInfo(x)).ToList()); if (Dialog.Ask("ScreenToGif", LocalizationHelper.Get("TempFiles.KeepRecent"), LocalizationHelper.Get("TempFiles.KeepRecent.Info"))) { _folderList = await Task.Factory.StartNew(() => _folderList.Where(w => (DateTime.Now - w.CreationTime).Days > 5).ToList()); } foreach (var folder in _folderList) { if (MutexList.IsInUse(folder.Name)) { continue; } Directory.Delete(folder.FullName, true); } _folderList = await Task.Factory.StartNew(() => Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly).Select(x => new DirectoryInfo(x)).ToList()); } catch (Exception ex) { LogWriter.Log(ex, "Error while cleaning the Temp folder"); } finally { App.MainViewModel.CheckDiskSpace(); } ClearTempButton.IsEnabled = _folderList.Any(); }
internal void ClearTemporaryFilesTask() { try { if (!UserSettings.All.AutomaticCleanUp || Global.IsCurrentlyDeletingFiles || string.IsNullOrWhiteSpace(UserSettings.All.TemporaryFolderResolved)) { return; } Global.IsCurrentlyDeletingFiles = true; var path = Path.Combine(UserSettings.All.TemporaryFolderResolved, "ScreenToGif", "Recording"); if (!Directory.Exists(path)) { return; } var list = Directory.GetDirectories(path).Select(x => new DirectoryInfo(x)) .Where(w => (DateTime.Now - w.CreationTime).TotalDays > (UserSettings.All.AutomaticCleanUpDays > 0 ? UserSettings.All.AutomaticCleanUpDays : 5)).ToList(); //var list = Directory.GetDirectories(path).Select(x => new DirectoryInfo(x)); foreach (var folder in list) { if (MutexList.IsInUse(folder.Name)) { continue; } Directory.Delete(folder.FullName, true); } } catch (Exception ex) { LogWriter.Log(ex, "Automatic clean up"); } finally { Global.IsCurrentlyDeletingFiles = false; CheckDiskSpace(); } }
public void ReleaseMutex() { MutexList.Remove(RelativePath); }
public void Clear() { Frames?.Clear(); MutexList.Remove(RelativePath); }