Skip to content

Commit

Permalink
Naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Aug 22, 2021
1 parent 854738b commit 460d0bc
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 187 deletions.
6 changes: 3 additions & 3 deletions Code/FFmpeg/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FFmpeg
public static async Task Run(string args)
{
lastOutputFfmpeg = "";
Process ffmpeg = OSUtils.NewProcess(true);
Process ffmpeg = OsUtils.NewProcess(true);
ffmpeg.StartInfo.Arguments = $"/C cd /D {Paths.binPath.Wrap()} & ffmpeg.exe -hide_banner -loglevel warning -y -stats {args}";
Logger.Log("Running ffmpeg...");
Logger.Log("cmd.exe " + ffmpeg.StartInfo.Arguments);
Expand Down Expand Up @@ -42,7 +42,7 @@ static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)

public static async Task RunGifski (string args)
{
Process ffmpeg = OSUtils.NewProcess(true);
Process ffmpeg = OsUtils.NewProcess(true);
ffmpeg.StartInfo.Arguments = $"/C cd /D {Paths.binPath.Wrap()} & gifski.exe {args}";
Logger.Log("Running gifski...");
Logger.Log("cmd.exe " + ffmpeg.StartInfo.Arguments);
Expand Down Expand Up @@ -70,7 +70,7 @@ static void OutputHandlerGifski (object sendingProcess, DataReceivedEventArgs ou

public static string RunAndGetOutput (string args)
{
Process ffmpeg = OSUtils.NewProcess(true);
Process ffmpeg = OsUtils.NewProcess(true);
ffmpeg.StartInfo.Arguments = $"/C cd /D {Paths.binPath.Wrap()} & ffmpeg.exe -hide_banner -y -stats {args}";
ffmpeg.Start();
ffmpeg.WaitForExit();
Expand Down
14 changes: 7 additions & 7 deletions Code/FFmpeg/FFmpegCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static async void ExtractSingleFrame(string inputFile, int frameNum, bool

public static async Task FramesToMp4 (string inputDir, bool useH265, int crf, float fps, string prefix, bool delSrc)
{
int nums = IOUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
int nums = IoUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
string enc = "libx264";
if (useH265) enc = "libx265";
string args = " -framerate " + fps.ToString().Replace(",", ".") + " -i \"" + inputDir + "\\" + prefix + "%0" + nums + "d.png\" -c:v " + enc
Expand All @@ -52,7 +52,7 @@ public static async Task FramesToMp4 (string inputDir, bool useH265, int crf, fl

public static async Task FramesToOneFpsMp4(string inputDir, bool useH265, int crf, int loopTimes, string prefix, bool delSrc)
{
int nums = IOUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
int nums = IoUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
string enc = "libx264";
if (useH265) enc = "libx265";
string args = " -framerate 1 -stream_loop " + loopTimes + " -i \"" + inputDir + "\\" + prefix + "%0" + nums + "d.png\" -c:v " + enc + " -r 30"
Expand All @@ -64,7 +64,7 @@ public static async Task FramesToOneFpsMp4(string inputDir, bool useH265, int cr

public static async Task FramesToMp4Looped(string inputDir, bool useH265, int crf, int fps, int loopTimes, string prefix, bool delSrc)
{
int nums = IOUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
int nums = IoUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
string enc = "libx264";
if (useH265) enc = "libx265";
string args = " -framerate " + fps + " -stream_loop " + loopTimes + " -i \"" + inputDir + "\\" + prefix + "%0" + nums + "d.png\" -c:v " + enc
Expand All @@ -76,7 +76,7 @@ public static async Task FramesToMp4Looped(string inputDir, bool useH265, int cr

public static async void FramesToApng (string inputDir, bool opti, int fps, string prefix, bool delSrc)
{
int nums = IOUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
int nums = IoUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
string filter = "";
if(opti) filter = "-vf \"split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse\"";
string args = "-framerate " + fps + " -i \"" + inputDir + "\\" + prefix + "%0" + nums + "d.png\" -f apng -plays 0 " + filter + " \"" + inputDir + "-anim.png\"";
Expand All @@ -87,7 +87,7 @@ public static async void FramesToApng (string inputDir, bool opti, int fps, stri

public static async Task FramesToGif (string inputDir, bool opti, int fps, string prefix, bool delSrc)
{
int nums = IOUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
int nums = IoUtils.GetFilenameCounterLength(Directory.GetFiles(inputDir, "*.png")[0], prefix);
string filter = "";
if (opti) filter = "-vf \"split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse\"";
string args = "-framerate " + fps + " -i \"" + inputDir + "\\" + prefix + "%0" + nums + "d.png\" -f gif " + filter + " \"" + inputDir + ".gif\"";
Expand Down Expand Up @@ -186,10 +186,10 @@ public static float GetFramerate (string inputFile)
static void DeleteSource (string path)
{
Logger.Log("Deleting input file/dir: " + path);
if (!IOUtils.IsPathDirectory(path) && File.Exists(path))
if (!IoUtils.IsPathDirectory(path) && File.Exists(path))
File.Delete(path);

if (IOUtils.IsPathDirectory(path) && Directory.Exists(path))
if (IoUtils.IsPathDirectory(path) && Directory.Exists(path))
Directory.Delete(path, true);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Code/Forms/DependencyCheckerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ string GetEmbedPyVersion()

string GetSysPythonOutput ()
{
Process py = OSUtils.NewProcess(true);
Process py = OsUtils.NewProcess(true);
py.StartInfo.Arguments = "/C python -V";
Logger.Log("[DepCheck] CMD: " + py.StartInfo.Arguments);
py.Start();
Expand All @@ -253,7 +253,7 @@ string GetSysPythonOutput ()

string GetEmbedPythonOutput ()
{
Process py = OSUtils.NewProcess(true);
Process py = OsUtils.NewProcess(true);
py.StartInfo.Arguments = "/C " + EmbeddedPython.GetEmbedPyPath().Wrap() + " -V";
Logger.Log("[DepCheck] CMD: " + py.StartInfo.Arguments);
py.Start();
Expand All @@ -268,7 +268,7 @@ string GetPytorchVer ()
{
try
{
Process py = OSUtils.NewProcess(true);
Process py = OsUtils.NewProcess(true);
py.StartInfo.Arguments = "\"/C\" " + EmbeddedPython.GetPyCmd() + " -c \"import torch; print(torch.__version__)\"";
Logger.Log("[DepCheck] CMD: " + py.StartInfo.Arguments);
py.Start();
Expand All @@ -289,7 +289,7 @@ string GetOpenCvVer()
{
try
{
Process py = OSUtils.NewProcess(true);
Process py = OsUtils.NewProcess(true);
py.StartInfo.Arguments = "\"/C\" " + EmbeddedPython.GetPyCmd() + " -c \"import cv2; print(cv2.__version__)\"";
Logger.Log("[DepCheck] CMD: " + py.StartInfo.Arguments);
py.Start();
Expand Down
4 changes: 2 additions & 2 deletions Code/Forms/InterpForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public AdvancedModelsForm(string leftModel, string rightModel)

private void InterpForm_Load(object sender, EventArgs e)
{
interpSlider.Value = PreviewUI.interpValue / 5;
interpSlider.Value = PreviewUi.interpValue / 5;
UpdateLabels();
}

private void saveBtn_Click(object sender, EventArgs e)
{
PreviewUI.interpValue = interpSlider.Value * 5;
PreviewUi.interpValue = interpSlider.Value * 5;
Close();
}

Expand Down
22 changes: 11 additions & 11 deletions Code/Forms/ModelComparisonForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public ModelComparisonForm()

private void ModelComparisonForm_Load(object sender, EventArgs e)
{
UIHelpers.InitCombox(compositionMode, 0);
UIHelpers.InitCombox(comparisonMode, 0);
UIHelpers.InitCombox(scaleFactor, 2);
UIHelpers.InitCombox(cropMode, 0);
UiHelpers.InitCombox(compositionMode, 0);
UiHelpers.InitCombox(comparisonMode, 0);
UiHelpers.InitCombox(scaleFactor, 2);
UiHelpers.InitCombox(cropMode, 0);

if (ModelComparisonTool.compositionModeComboxIndex >= 0)
compositionMode.SelectedIndex = ModelComparisonTool.compositionModeComboxIndex;
Expand Down Expand Up @@ -63,7 +63,7 @@ private void addModelBtn_Click(object sender, EventArgs e)

private async void runBtn_Click(object sender, EventArgs e)
{
if(PreviewUI.previewImg.Image == null || !File.Exists(Paths.tempImgPath))
if(PreviewUi.previewImg.Image == null || !File.Exists(Paths.tempImgPath))
{
Program.ShowMessage("No image loaded!", "Error");
return;
Expand All @@ -72,8 +72,8 @@ private async void runBtn_Click(object sender, EventArgs e)
cutoutMode = cropMode.SelectedIndex == 1;
if (cutoutMode)
{
IOUtils.ClearDir(Paths.previewPath);
PreviewUI.SaveCurrentCutout();
IoUtils.ClearDir(Paths.previewPath);
PreviewUi.SaveCurrentCutout();
currentSourcePath = Path.Combine(Paths.previewPath, "preview.png");
}
else
Expand All @@ -100,7 +100,7 @@ private async void runBtn_Click(object sender, EventArgs e)
mergedPath = Path.ChangeExtension(mergedPath, GetSaveExt());
merged.Write(mergedPath);
await Upscale.CopyImagesTo(Program.lastImgPath.GetParentDir());
IOUtils.ClearDir(Paths.previewPath);
IoUtils.ClearDir(Paths.previewPath);
Enabled = true;
Program.ShowMessage("Saved model composition to " + Program.lastImgPath.GetParentDir() + "\\" + Path.GetFileName(mergedPath), "Message");
}
Expand All @@ -127,7 +127,7 @@ static string GetSaveExt ()

async Task DoUpscale (int index, ModelData mdl, bool fullImage)
{
if (PreviewUI.previewImg.Image == null)
if (PreviewUi.previewImg.Image == null)
{
Program.ShowMessage("Please load an image first!", "Error");
return;
Expand All @@ -149,8 +149,8 @@ async Task DoUpscale (int index, ModelData mdl, bool fullImage)
await ESRGAN.DoUpscale(inpath, Paths.compositionOut, mdl, false, Config.GetBool("alpha"), ESRGAN.PreviewMode.None);
outImg = Directory.GetFiles(Paths.compositionOut, ".*.png*", SearchOption.AllDirectories)[0];
await PostProcessing.PostprocessingSingle(outImg, false);
await ProcessImage(PreviewUI.lastOutfile, mdl.model1Name);
IOUtils.TryCopy(PreviewUI.lastOutfile, Path.Combine(Paths.imgOutPath, $"{index}-{mdl.model1Name}.png"), true);
await ProcessImage(PreviewUi.lastOutfile, mdl.model1Name);
IoUtils.TryCopy(PreviewUi.lastOutfile, Path.Combine(Paths.imgOutPath, $"{index}-{mdl.model1Name}.png"), true);
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions Code/Forms/ModelSelectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void ModelSelectForm_Load(object sender, EventArgs e)
return;
}

if (IOUtils.GetAmountOfFiles(modelDir, true, "*.pth") < 1)
if (IoUtils.GetAmountOfFiles(modelDir, true, "*.pth") < 1)
{
Program.ShowMessage($"The saved model directory does not contain any model (.pth) files!\n\nPlease put some models into '{modelDir}'.");
Close();
Expand Down Expand Up @@ -83,7 +83,7 @@ private void CheckNodesRecursive(TreeNode parentNode)

private void ForceLowercaseExtensions(string path)
{
foreach (FileInfo file in IOUtils.GetFileInfosSorted(path, true, "*.*"))
foreach (FileInfo file in IoUtils.GetFileInfosSorted(path, true, "*.*"))
{
if(file.Extension == ".PTH")
file.MoveTo(Path.ChangeExtension(file.FullName, "pth"));
Expand Down
2 changes: 1 addition & 1 deletion Code/IO/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Cupscale
{
internal class IOUtils
internal class IoUtils
{
public static string[] compatibleExtensions = new string[] { ".png", ".jpg", ".jpeg", ".bmp", ".tga", ".webp", ".dds", ".gif" };
public static string[] videoExtensions = new string[] { ".mp4", ".m4v", ".mkv", ".webm", ".gif", ".avi" };
Expand Down
4 changes: 2 additions & 2 deletions Code/IO/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static bool InstallationIsValid ()
}
}

int diskVersion = IOUtils.ReadLines(Path.Combine(Paths.GetDataPath(), "shipped-files-version.txt"))[0].Split('#')[0].GetInt();
int diskVersion = IoUtils.ReadLines(Path.Combine(Paths.GetDataPath(), "shipped-files-version.txt"))[0].Split('#')[0].GetInt();
if (exeFilesVersion != diskVersion)
{
Logger.Log("[Installer] Installation invalid: Shipped file version mismatch - Executable is " + exeFilesVersion + ", installation is " + diskVersion);
Expand All @@ -84,7 +84,7 @@ public static async Task Install ()
DialogForm dialog = new DialogForm("Installing resources...\nThis only needs to be done once.");
await Task.Delay(20);

if (IOUtils.GetDirSize(path) > 0)
if (IoUtils.GetDirSize(path) > 0)
{
Logger.Log("[Installer] {path} is not 0 bytes - removing everything there to ensure a clean install.");
dialog.ChangeText("Uninstalling older files...");
Expand Down
6 changes: 3 additions & 3 deletions Code/IO/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public static string GetDataPath()
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
path = Path.Combine(path, "Cupscale");

if (IOUtils.IsPortable())
if (IoUtils.IsPortable())
{
if (!IOUtils.hasShownPortableInfo)
if (!IoUtils.hasShownPortableInfo)
{
Logger.Log("Running in portable mode. Data folder: " + Path.Combine(GetExeDir(), "CupscaleData"), false);
IOUtils.hasShownPortableInfo = true;
IoUtils.hasShownPortableInfo = true;
}
path = Path.Combine(GetExeDir(), "CupscaleData");
}
Expand Down
8 changes: 4 additions & 4 deletions Code/ImageUtils/ImageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static async Task ConvertImage(string path, Format format, bool fillAlpha
if (File.Exists(outPath))
{
if (Logger.doLogIo) Logger.Log("[ImgProc] File exists at - making sure it doesn't have readonly flag");
IOUtils.RemoveReadonlyFlag(outPath);
IoUtils.RemoveReadonlyFlag(outPath);
}

bool inPathIsOutPath = outPath.ToLower() == path.ToLower();
Expand All @@ -209,7 +209,7 @@ public static async Task ConvertImage(string path, Format format, bool fillAlpha
File.Delete(path);
}
img.Dispose();
IOUtils.RemoveReadonlyFlag(outPath);
IoUtils.RemoveReadonlyFlag(outPath);
await Task.Delay(1);
}

Expand Down Expand Up @@ -330,7 +330,7 @@ public static async Task PostProcessImage(string path, Format format, bool dontR
PostProcessingQueue.lastOutfile = outPath;

if (Upscale.currentMode == Upscale.UpscaleMode.Single || Upscale.currentMode == Upscale.UpscaleMode.Composition)
PreviewUI.lastOutfile = outPath;
PreviewUi.lastOutfile = outPath;

if (magick)
{
Expand Down Expand Up @@ -364,7 +364,7 @@ public static async Task PostProcessDDS(string path)
PostProcessingQueue.lastOutfile = outPath;

if (Upscale.currentMode == Upscale.UpscaleMode.Single || Upscale.currentMode == Upscale.UpscaleMode.Composition)
PreviewUI.lastOutfile = outPath;
PreviewUi.lastOutfile = outPath;

if (outPath.ToLower() != path.ToLower())
{
Expand Down
2 changes: 1 addition & 1 deletion Code/Implementations/EsrganNcnn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static async Task Run(string inpath, string outpath, ModelData mdl)
$" -g {Config.GetInt("esrganNcnnGpu")} -m {NcnnUtils.currentNcnnModel.Wrap()} -s {scale} {tta} {ts}";
Logger.Log("[CMD] " + cmd);

Process ncnnProcess = OSUtils.NewProcess(!showWindow);
Process ncnnProcess = OsUtils.NewProcess(!showWindow);
ncnnProcess.StartInfo.Arguments = cmd;

if (!showWindow)
Expand Down
8 changes: 4 additions & 4 deletions Code/Implementations/EsrganPytorch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static async Task Run(string inpath, string outpath, ModelData mdl, bool
string cmd = $"{opt} cd /D {Path.Combine(Paths.binPath, Imps.esrganPytorch.dir).Wrap()} & ";
cmd += $"{EmbeddedPython.GetPyCmd()} upscale.py --input {inpath} --output {outpath} {cache} {cpu} {device} {fp16} {seam} {alphaMode} {alphaDepth} {modelArg}";
Logger.Log("[CMD] " + cmd);
Process esrganProcess = OSUtils.NewProcess(!showWindow);
Process esrganProcess = OsUtils.NewProcess(!showWindow);
esrganProcess.StartInfo.Arguments = cmd;

if (!showWindow)
Expand Down Expand Up @@ -134,7 +134,7 @@ public static string Interpolate(ModelData mdl)
bool showWindow = Config.GetInt("cmdDebugMode") > 0;
bool stayOpen = Config.GetInt("cmdDebugMode") == 2;

Process py = OSUtils.NewProcess(!showWindow);
Process py = OsUtils.NewProcess(!showWindow);

string opt = stayOpen ? "/K" : "/C";
string alphaStr = (mdl.interp / 100f).ToString("0.00").Replace(",", ".");
Expand Down Expand Up @@ -189,7 +189,7 @@ private static void OutputHandler(object sendingProcess, DataReceivedEventArgs o
if (data.Contains("UnpicklingError"))
Program.ShowMessage("Failed to load model!", "Error");

if (PreviewUI.currentMode == PreviewUI.Mode.Interp && (data.Contains("must match the size of tensor b") || data.Contains("KeyError: 'model.")))
if (PreviewUi.currentMode == PreviewUi.Mode.Interp && (data.Contains("must match the size of tensor b") || data.Contains("KeyError: 'model.")))
Program.ShowMessage("It seems like you tried to interpolate incompatible models!", "Error");
}

Expand All @@ -202,7 +202,7 @@ private static async Task UpdateProgressFromFile()
if (!File.Exists(progressLogFile))
return;

string[] lines = IOUtils.ReadLines(progressLogFile);
string[] lines = IoUtils.ReadLines(progressLogFile);

if (lines.Length < 1)
return;
Expand Down
2 changes: 1 addition & 1 deletion Code/Implementations/RealEsrganNcnn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static async Task Run(string inpath, string outpath, ModelData mdl)
$" -g {Config.GetInt("realEsrganNcnnGpus")} -m {NcnnUtils.currentNcnnModel.Wrap()} -n esrgan-x4 -s {scale} {tta} {ts}";
Logger.Log("[CMD] " + cmd);

Process proc = OSUtils.NewProcess(!showWindow);
Process proc = OsUtils.NewProcess(!showWindow);
proc.StartInfo.Arguments = cmd;

if (!showWindow)
Expand Down
2 changes: 1 addition & 1 deletion Code/Main/AdvancedModelSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static bool LoadPreset(string name)
if (!File.Exists(path))
return false;

string[] saveDataLines = IOUtils.ReadLines(path);
string[] saveDataLines = IoUtils.ReadLines(path);
foreach(string line in saveDataLines)
{
string[] keyValuePair = line.Split('|');
Expand Down
Loading

0 comments on commit 460d0bc

Please sign in to comment.