public static void Init() { file = Path.Combine(IOUtils.GetAppDataDir(), "sessionlog.txt"); doLogIo = Config.GetBool("logIo"); doLogStatus = Config.GetBool("logStatus"); PrintArgs(); }
private static void Main() { try { string lockfile = Path.Combine(IOUtils.GetAppDataDir(), "lockfile"); File.Create(lockfile).Dispose(); FileStream fs = File.Open(lockfile, FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch { MessageBox.Show("Another instance of Cupscale seems to be running, accessing the following data folder:\n" + IOUtils.GetAppDataDir() + ".\n\nMultiple instance are only possible if they use different data folders.\n" + "Starting Cupscale with \"-portable\" will use the current directory as data folder.", "Error"); return; } Application.SetCompatibleTextRenderingDefault(defaultValue: false); Application.EnableVisualStyles(); IOUtils.DeleteIfExists(Path.Combine(IOUtils.GetAppDataDir(), "sessionlog.txt")); Config.Init(); Logger.Init(); Paths.Init(); ResourceLimits.Memory = (ulong)Math.Round(ResourceLimits.Memory * 1.5f); Cleanup(); Application.Run(new MainForm()); }
public static void Init() { configPath = Path.Combine(IOUtils.GetAppDataDir(), "config.ini"); if (!File.Exists(configPath)) { File.Create(configPath).Close(); } Reload(); }
private static void Main() { Application.SetCompatibleTextRenderingDefault(defaultValue: false); Application.EnableVisualStyles(); IOUtils.DeleteIfExists(Path.Combine(IOUtils.GetAppDataDir(), "sessionlog.txt")); Config.Init(); Logger.Init(); Paths.Init(); ResourceLimits.Memory = (ulong)Math.Round(ResourceLimits.Memory * 1.5f); Cleanup(); Application.Run(new MainForm()); }
public static void Cleanup() { try { IOUtils.ClearDir(Paths.previewPath); IOUtils.ClearDir(Paths.previewOutPath); IOUtils.ClearDir(Paths.clipboardFolderPath); IOUtils.ClearDir(Paths.imgInPath); IOUtils.ClearDir(Paths.imgOutPath); IOUtils.ClearDir(Paths.imgOutNcnnPath); IOUtils.ClearDir(Paths.tempImgPath.GetParentDir()); IOUtils.ClearDir(Path.Combine(IOUtils.GetAppDataDir(), "giftemp")); IOUtils.DeleteIfExists(Path.Combine(Paths.presetsPath, "lastUsed")); IOUtils.ClearDir(Paths.compositionOut); } catch (Exception e) { Logger.Log("Error during cleanup: " + e.Message); } }
public static void LogToFile(string s, bool noLineBreak) { if (string.IsNullOrWhiteSpace(file)) { file = Path.Combine(IOUtils.GetAppDataDir(), "sessionlog.txt"); } string time = DT.Now.Month + "-" + DT.Now.Day + "-" + DT.Now.Year + " " + DT.Now.Hour + ":" + DT.Now.Minute + ":" + DT.Now.Second; try { if (!noLineBreak) { File.AppendAllText(file, Environment.NewLine + time + ": " + s); } else { File.AppendAllText(file, " " + s); } } catch { // idk how to deal with this race condition (?) but just ignoring it seems to work lol } }
public static async void BeforeAfterAnim(bool save, bool h264) { string ext = "gif"; if (h264) { ext = "mp4"; } DialogForm dialogForm = new DialogForm("Creating comparison " + ext.ToUpper() + "..."); string tempPath = Path.Combine(IOUtils.GetAppDataDir(), "giftemp"); string framesPath = Path.Combine(tempPath, "frames"); IOUtils.ClearDir(tempPath); Directory.CreateDirectory(framesPath); resultPreview = (Bitmap)ImgUtils.GetImage(Directory.GetFiles(IO.Paths.previewOutPath, "*.png.*", SearchOption.AllDirectories)[0]); Image image1 = originalPreview; Image image2 = resultPreview; if (Config.GetInt("comparisonUseScaling") == 1) { image1 = (Bitmap)ImgUtils.GetImage(Path.Combine(IO.Paths.previewPath, "preview.png.png")); } float scale = (float)image2.Width / (float)image1.Width; Logger.Log("Scale for animation: " + scale); string outpath = Path.Combine(tempPath, "comparison." + ext); if (image2.Width <= 2048 && image2.Height <= 2048) { image1.Scale(scale, InterpolationMode.NearestNeighbor).Save(Path.Combine(framesPath, "0.png")); image2.Save(Path.Combine(framesPath, "1.png")); if (h264) { await FFmpegCommands.FramesToOneFpsMp4(framesPath, false, 14, 9, "", false); File.Move(Path.Combine(tempPath, "frames." + ext), outpath); } else { await FFmpeg.RunGifski(" -r 1 -W 2048 -q -o " + outpath.Wrap() + " \"" + framesPath + "/\"*.\"png\""); } if (save) { string comparisonSavePath = Path.ChangeExtension(Program.lastFilename, null) + "-comparison." + ext; File.Copy(outpath, comparisonSavePath, true); dialogForm.Close(); Program.ShowMessage("Saved current comparison to:\n\n" + comparisonSavePath, "Message"); } else { StringCollection paths = new StringCollection(); paths.Add(outpath); Clipboard.SetFileDropList(paths); dialogForm.Close(); Program.ShowMessage("The " + ext.ToUpper() + " file has been copied. You can paste it into any folder.\n" + "Please note that pasting it into Discord or other programs won't work as the clipboard can't hold animated images.", "Message"); } } else { Program.ShowMessage("The preview is too large for making an animation. Please create a smaller cutout or choose a different comparison type.", "Error"); } dialogForm.Close(); }