public static void CheckOs() { if (!File.Exists(Paths.GetVerPath()) && Paths.GetExeDir().ToLower().Contains("temp")) { MessageBox.Show("You seem to be running Flowframes out of an archive.\nPlease extract the whole archive first!", "Error"); IoUtils.TryDeleteIfExists(Paths.GetDataPath()); Application.Exit(); } string[] osInfo = OsUtils.TryGetOs().Split(" | "); string version = osInfo[0].Remove("Microsoft").Trim(); if (Is32Bit() && !Config.GetBool("allow32Bit", false)) { MessageBox.Show("This application is not compatible with 32 bit operating systems!", "Error"); Application.Exit(); } if (string.IsNullOrWhiteSpace(version)) { return; } if (!version.ToLower().Contains("windows 10") && !version.ToLower().Contains("windows 11") && !Config.GetBool("ignoreIncompatibleOs", false)) { MessageBox.Show($"This application was made for Windows 10/11 and is not officially compatible with {version}.\n\n" + $"Use it at your own risk and do NOT ask for support as long as your are on {version}.", "Warning"); } }
public static async Task RunFlavrCudaProcess(string inPath, string outDir, string script, float interpFactor, string mdl) { string outPath = Path.Combine(inPath.GetParentDir(), outDir); Directory.CreateDirectory(outPath); string args = $" --input {inPath.Wrap()} --output {outPath.Wrap()} --model {mdl}/{mdl}.pth --factor {interpFactor}"; Process flavrPy = OsUtils.NewProcess(!OsUtils.ShowHiddenCmd()); AiStarted(flavrPy, 4000); SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor); flavrPy.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {Path.Combine(Paths.GetPkgPath(), Implementations.flavrCuda.pkgDir).Wrap()} & " + $"set CUDA_VISIBLE_DEVICES={Config.Get(Config.Key.torchGpus)} & {Python.GetPyCmd()} {script} {args}"; Logger.Log($"Running FLAVR (CUDA)...", false); Logger.Log("cmd.exe " + flavrPy.StartInfo.Arguments, true); if (!OsUtils.ShowHiddenCmd()) { flavrPy.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "flavr-cuda-log"); }; flavrPy.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "flavr-cuda-log", true); }; } flavrPy.Start(); if (!OsUtils.ShowHiddenCmd()) { flavrPy.BeginOutputReadLine(); flavrPy.BeginErrorReadLine(); } while (!flavrPy.HasExited) { await Task.Delay(1); } }
static string GetSysPythonOutput() { Process py = OsUtils.NewProcess(true); py.StartInfo.Arguments = "/C python -V"; Logger.Log("[DepCheck] CMD: " + py.StartInfo.Arguments, true); py.Start(); py.WaitForExit(); string output = py.StandardOutput.ReadToEnd(); string err = py.StandardError.ReadToEnd(); return(output + "\n" + err); }
static bool Is32Bit() { string osInfoStr = OsUtils.TryGetOs(); if (string.IsNullOrWhiteSpace(osInfoStr)) { return(false); // If it fails, assume we are on 64bit } string[] osInfo = osInfoStr.Split(" | "); string arch = osInfo[1].Trim(); return(arch.Contains("32")); }
static bool IsWin10Or11() { string osInfoStr = OsUtils.TryGetOs(); if (string.IsNullOrWhiteSpace(osInfoStr)) { return(true); // If it fails, assume we are on Win10 } string[] osInfo = osInfoStr.Split(" | "); string version = osInfo[0].Remove("Microsoft").Trim(); return(version.ToLower().Contains("windows 10") || version.ToLower().Contains("windows 11")); }
public static void Kill() { if (lastAiProcess == null) { return; } try { AiProcessSuspend.SetRunning(false); OsUtils.KillProcessTree(lastAiProcess.Id); } catch (Exception e) { Logger.Log($"Failed to kill currentAiProcess process tree: {e.Message}", true); } }
public static async Task RunRifeCudaProcess(string inPath, string outDir, string script, float interpFactor, string mdl) { string outPath = Path.Combine(inPath.GetParentDir(), outDir); Directory.CreateDirectory(outPath); string uhdStr = await InterpolateUtils.UseUhd() ? "--UHD" : ""; string wthreads = $"--wthreads {2 * (int)interpFactor}"; string rbuffer = $"--rbuffer {Config.GetInt(Config.Key.rifeCudaBufferSize, 200)}"; //string scale = $"--scale {Config.GetFloat("rifeCudaScale", 1.0f).ToStringDot()}"; string prec = Config.GetBool(Config.Key.rifeCudaFp16) ? "--fp16" : ""; string args = $" --input {inPath.Wrap()} --output {outDir} --model {mdl} --multi {interpFactor} {uhdStr} {wthreads} {rbuffer} {prec}"; Process rifePy = OsUtils.NewProcess(!OsUtils.ShowHiddenCmd()); AiStarted(rifePy, 3500); SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor); rifePy.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {Path.Combine(Paths.GetPkgPath(), Implementations.rifeCuda.pkgDir).Wrap()} & " + $"set CUDA_VISIBLE_DEVICES={Config.Get(Config.Key.torchGpus)} & {Python.GetPyCmd()} {script} {args}"; Logger.Log($"Running RIFE (CUDA){(await InterpolateUtils.UseUhd() ? " (UHD Mode)" : "")}...", false); Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true); if (!OsUtils.ShowHiddenCmd()) { rifePy.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "rife-cuda-log"); }; rifePy.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "rife-cuda-log", true); }; } rifePy.Start(); if (!OsUtils.ShowHiddenCmd()) { rifePy.BeginOutputReadLine(); rifePy.BeginErrorReadLine(); } while (!rifePy.HasExited) { await Task.Delay(1); } }
public static async Task RunXvfiCudaProcess(string inPath, string outDir, string script, float interpFactor, string mdlDir) { string pkgPath = Path.Combine(Paths.GetPkgPath(), Implementations.xvfiCuda.pkgDir); string basePath = inPath.GetParentDir(); string outPath = Path.Combine(basePath, outDir); Directory.CreateDirectory(outPath); string mdlArgs = File.ReadAllText(Path.Combine(pkgPath, mdlDir, "args.ini")); string args = $" --custom_path {basePath.Wrap()} --input {inPath.Wrap()} --output {outPath.Wrap()} --mdl_dir {mdlDir}" + $" --multiple {interpFactor} --gpu 0 {mdlArgs}"; Process xvfiPy = OsUtils.NewProcess(!OsUtils.ShowHiddenCmd()); AiStarted(xvfiPy, 3500); SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor); xvfiPy.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {pkgPath.Wrap()} & " + $"set CUDA_VISIBLE_DEVICES={Config.Get(Config.Key.torchGpus)} & {Python.GetPyCmd()} {script} {args}"; Logger.Log($"Running XVFI (CUDA)...", false); Logger.Log("cmd.exe " + xvfiPy.StartInfo.Arguments, true); if (!OsUtils.ShowHiddenCmd()) { xvfiPy.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "xvfi-cuda-log"); }; xvfiPy.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "xvfi-cuda-log", true); }; } xvfiPy.Start(); if (!OsUtils.ShowHiddenCmd()) { xvfiPy.BeginOutputReadLine(); xvfiPy.BeginErrorReadLine(); } while (!xvfiPy.HasExited) { await Task.Delay(1); } }
public static async Task CheckCompression() { if (HasEmbeddedPyFolder() && (Config.Get(Config.Key.compressedPyVersion) != Updater.GetInstalledVer().ToString())) { Program.mainForm.SetWorking(true, false); Stopwatch sw = new Stopwatch(); sw.Restart(); try { bool shownPatienceMsg = false; Logger.Log("Compressing python runtime. This only needs to be done once."); compactOutput = ""; Process compact = OsUtils.NewProcess(true); compact.StartInfo.Arguments = $"/C compact /C /S:{GetPyFolder().Wrap()} /EXE:LZX"; compact.OutputDataReceived += new DataReceivedEventHandler(CompactOutputHandler); compact.ErrorDataReceived += new DataReceivedEventHandler(CompactOutputHandler); compact.Start(); compact.BeginOutputReadLine(); compact.BeginErrorReadLine(); while (!compact.HasExited) { await Task.Delay(500); if (sw.ElapsedMilliseconds > 10000) { Logger.Log($"This can take up to a few minutes, but only needs to be done once. (Elapsed: {FormatUtils.Time(sw.Elapsed)})", false, shownPatienceMsg); shownPatienceMsg = true; await Task.Delay(500); } } Config.Set("compressedPyVersion", Updater.GetInstalledVer().ToString()); Logger.Log("Done compressing python runtime."); Logger.WriteToFile(compactOutput, true, "compact"); } catch { } Program.mainForm.SetWorking(false); } }
static async Task RunRifeNcnnProcess(string inPath, float factor, string outPath, string mdl) { Directory.CreateDirectory(outPath); Process rifeNcnn = OsUtils.NewProcess(!OsUtils.ShowHiddenCmd()); AiStarted(rifeNcnn, 1500, inPath); SetProgressCheck(outPath, factor); int targetFrames = ((IoUtils.GetAmountOfFiles(lastInPath, false, "*.*") * factor).RoundToInt()); // TODO: Maybe won't work with fractional factors ?? string frames = mdl.Contains("v4") ? $"-n {targetFrames}" : ""; string uhdStr = await InterpolateUtils.UseUhd() ? "-u" : ""; string ttaStr = Config.GetBool(Config.Key.rifeNcnnUseTta, false) ? "-x" : ""; rifeNcnn.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnn.pkgDir).Wrap()} & rife-ncnn-vulkan.exe " + $" -v -i {inPath.Wrap()} -o {outPath.Wrap()} {frames} -m {mdl.ToLower()} {ttaStr} {uhdStr} -g {Config.Get(Config.Key.ncnnGpus)} -f {GetNcnnPattern()} -j {GetNcnnThreads()}"; Logger.Log("cmd.exe " + rifeNcnn.StartInfo.Arguments, true); if (!OsUtils.ShowHiddenCmd()) { rifeNcnn.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "rife-ncnn-log"); }; rifeNcnn.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "rife-ncnn-log", true); }; } rifeNcnn.Start(); if (!OsUtils.ShowHiddenCmd()) { rifeNcnn.BeginOutputReadLine(); rifeNcnn.BeginErrorReadLine(); } while (!rifeNcnn.HasExited) { await Task.Delay(1); } }
static string GetPytorchVer() { try { Process py = OsUtils.NewProcess(true); py.StartInfo.Arguments = "\"/C\" " + GetPyCmd() + " -c \"import torch; print(torch.__version__)\""; Logger.Log("[DepCheck] CMD: " + py.StartInfo.Arguments); py.Start(); py.WaitForExit(); string output = py.StandardOutput.ReadToEnd(); string err = py.StandardError.ReadToEnd(); if (!string.IsNullOrWhiteSpace(err)) { output += "\n" + err; } Logger.Log("[DepCheck] Pytorch Check Output: " + output.Trim()); return(output); } catch { return(""); } }
public static async Task RunDainNcnnProcess(string framesPath, string outPath, float factor, string mdl, int tilesize) { string dainDir = Path.Combine(Paths.GetPkgPath(), Implementations.dainNcnn.pkgDir); Directory.CreateDirectory(outPath); Process dain = OsUtils.NewProcess(!OsUtils.ShowHiddenCmd()); AiStarted(dain, 1500); SetProgressCheck(outPath, factor); int targetFrames = ((IoUtils.GetAmountOfFiles(lastInPath, false, "*.*") * factor).RoundToInt()); string args = $" -v -i {framesPath.Wrap()} -o {outPath.Wrap()} -n {targetFrames} -m {mdl.ToLower()}" + $" -t {GetNcnnTilesize(tilesize)} -g {Config.Get(Config.Key.ncnnGpus)} -f {GetNcnnPattern()} -j 2:1:2"; dain.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {dainDir.Wrap()} & dain-ncnn-vulkan.exe {args}"; Logger.Log("Running DAIN...", false); Logger.Log("cmd.exe " + dain.StartInfo.Arguments, true); if (!OsUtils.ShowHiddenCmd()) { dain.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "dain-ncnn-log"); }; dain.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "dain-ncnn-log", true); }; } dain.Start(); if (!OsUtils.ShowHiddenCmd()) { dain.BeginOutputReadLine(); dain.BeginErrorReadLine(); } while (!dain.HasExited) { await Task.Delay(100); } }
public static async Task AsyncUpdateCheck() { Version installed = GetInstalledVer(); Version latestPat = GetLatestVer(true); Version latestFree = GetLatestVer(false); Logger.Log($"You are running Flowframes {installed}. The latest Patreon version is {latestPat}, the latest free version is {latestFree}."); string gpus = OsUtils.GetGpus().Remove("NVIDIA ").Remove("AMD ").Remove("Intel "); if (installed.ToString() != "0.0.0") { Program.mainForm.Text = $"Flowframes {installed}"; } else { Program.mainForm.Text = $"Flowframes [Unknown Version]"; } if (!string.IsNullOrWhiteSpace(gpus.Trim())) { Program.mainForm.Text = $"{Program.mainForm.Text} [GPU: {gpus}]"; } }
public static async Task SymlinksCheck() { if (!IsWin10Or11()) { return; } bool silent = Config.GetBool("silentDevmodeCheck", true); string ver = Updater.GetInstalledVer().ToString(); bool symlinksAllowed = Symlinks.SymlinksAllowed(); Logger.Log($"SymlinksAllowed: {symlinksAllowed}", true); if (!symlinksAllowed && Config.Get(Config.Key.askedForDevModeVersion) != ver) { if (!silent) { MessageBox.Show("Flowframes will now enable Windows' Developer Mode which is required for video encoding improvements.\n\n" + "This requires administrator privileges once.", "Message"); } Logger.Log($"Trying to enable dev mode.", true); string devmodeBatchPath = Path.Combine(Paths.GetDataPath(), "devmode.bat"); File.WriteAllText(devmodeBatchPath, Properties.Resources.devmode); Process devmodeProc = OsUtils.NewProcess(true); devmodeProc.StartInfo.Arguments = $"/C {devmodeBatchPath.Wrap()}"; devmodeProc.Start(); while (!devmodeProc.HasExited) { await Task.Delay(100); } bool symlinksWorksNow = false; for (int retries = 8; retries > 0; retries--) { symlinksWorksNow = Symlinks.SymlinksAllowed(); if (symlinksWorksNow) { break; } await Task.Delay(500); } if (!symlinksWorksNow) { if (!silent) { MessageBox.Show("Failed to enable developer mode - Perhaps you do not have sufficient privileges.\n\n" + "Without Developer Mode, video encoding will be noticably slower.\n\nYou can still try enabling " + "it manually in the Windows 10 Settings:\nSettings -> Update & security -> For developers -> Developer mode.", "Message"); } Logger.Log("Failed to enable dev mode.", true); Config.Set("askedForDevModeVersion", ver); } else { Logger.Log("Enabled Windows Developer Mode.", silent); } IoUtils.TryDeleteIfExists(devmodeBatchPath); } }
public static void SuspendResumeAi(bool freeze, bool excludeCmd = true) { if (AiProcess.lastAiProcess == null || AiProcess.lastAiProcess.HasExited) { return; } Process currProcess = AiProcess.lastAiProcess; Logger.Log($"{(freeze ? "Suspending" : "Resuming")} main process ({currProcess.StartInfo.FileName} {currProcess.StartInfo.Arguments})", true); if (freeze) { List <Process> procs = new List <Process>(); procs.Add(currProcess); foreach (var subProc in OsUtils.GetChildProcesses(currProcess)) { procs.Add(subProc); } aiProcFrozen = true; SetPauseButtonStyle(true); AiProcess.processTime.Stop(); foreach (Process process in procs) { if (process == null || process.HasExited) { continue; } if (excludeCmd && (process.ProcessName == "conhost" || process.ProcessName == "cmd")) { continue; } Logger.Log($"Suspending {process.ProcessName}", true); process.Suspend(); suspendedProcesses.Add(process); } } else { aiProcFrozen = false; SetPauseButtonStyle(false); AiProcess.processTime.Start(); foreach (Process process in new List <Process>(suspendedProcesses)) // We MUST clone the list here since we modify it in the loop! { if (process == null || process.HasExited) { continue; } Logger.Log($"Resuming {process.ProcessName}", true); process.Resume(); suspendedProcesses.Remove(process); } } }