Skip to content

Commit

Permalink
Fixed file extensions bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Sep 19, 2020
1 parent 446f475 commit 99e0245
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
11 changes: 5 additions & 6 deletions Code/Cupscale/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,20 @@ async Task DragNDrop (string [] array)
htTabControl.SelectedIndex = 0;
previewImg.Text = "";
SetProgress(0f, "Loading image...");
DialogForm loadingDialogForm = new DialogForm("Loading image...");
DialogForm loadingDialogForm = new DialogForm("Loading " + Path.GetFileName(path) +"...");
await Task.Delay(1);
MainUIHelper.ResetCachedImages();
if (!MainUIHelper.DroppedImageIsValid(array[0]))
if (!MainUIHelper.DroppedImageIsValid(path))
{
SetProgress(0f, "Ready.");
await Task.Delay(1);
Program.CloseTempForms();
return;
}
string imgTempPath = Path.Combine(Paths.imgInPath, "temp.png");
File.Copy(array[0], imgTempPath, true);
File.Copy(path, Paths.tempImgPath, true);
await Upscale.Preprocessing(Paths.imgInPath);
previewImg.Image = IOUtils.GetImage(imgTempPath);
Program.lastFilename = array[0];
previewImg.Image = IOUtils.GetImage(Paths.tempImgPath);
Program.lastFilename = path;
MainUIHelper.currentScale = 1;
previewImg.ZoomToFit();
loadingDialogForm.Close();
Expand Down
1 change: 1 addition & 0 deletions Code/Cupscale/Upscale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static string GetMdl(ComboBox box)
{
MessageBox.Show("Model file not found!", "Error");
Program.mainForm.SetProgress(0);
Program.mainForm.SetBusy(false);
return "";
}
return mdl;
Expand Down
6 changes: 3 additions & 3 deletions Code/Forms/DialogForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Code/IO/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,17 @@ public static void RenameExtensions (string dir, string oldExt, string newExt, b
files = d.GetFiles(wildcard, SearchOption.AllDirectories);
else
files = d.GetFiles(wildcard, SearchOption.TopDirectoryOnly);

string targetPath = "";
foreach (FileInfo file in files)
{
if (file.Extension.Replace(".","") == oldExt.Replace(".", ""))
Path.ChangeExtension(file.FullName, newExt);
{
targetPath = Path.ChangeExtension(file.FullName, newExt);
if (!File.Exists(targetPath))
File.Delete(targetPath);
File.Move(file.FullName, targetPath);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Code/IO/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal class Paths
public static string previewOutPath;
public static string imgInPath;
public static string imgOutPath;
public static string tempImgPath;
public static string progressLogfile;

public static void Init()
Expand All @@ -18,6 +19,7 @@ public static void Init()
previewOutPath = Path.Combine(IOUtils.GetAppDataDir(), "preview-out");
imgInPath = Path.Combine(IOUtils.GetAppDataDir(), "img-in");
imgOutPath = Path.Combine(IOUtils.GetAppDataDir(), "img-out");
tempImgPath = Path.Combine(IOUtils.GetAppDataDir(), "temp.png");
progressLogfile = Path.Combine(esrganPath, "prog");
Directory.CreateDirectory(previewPath);
Directory.CreateDirectory(previewOutPath);
Expand Down
10 changes: 5 additions & 5 deletions Code/ImageUtils/UpscaleProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public static async Task ConvertImagesToOriginalFormat()
{
format = Format.DDS;
}
await ConvertImage(file2.FullName, format, false, false, false);
await Task.Delay(1);
await ConvertImage(file2.FullName, format, false, false, true);
}
}

Expand Down Expand Up @@ -164,9 +163,10 @@ public static async Task ConvertImage(string path, Format format, bool fillAlpha
if (appendExtension)
{
string extension = Path.GetExtension(path);
Logger.Log("Appending old extension; writing image to " + Path.ChangeExtension(path, null) + extension + "." + text);
img.Write(Path.ChangeExtension(path, null) + extension + "." + text);
if (deleteSource && !(Path.ChangeExtension(path, null) + extension + "." + text == path))
string outPath = Path.ChangeExtension(path, null) + extension + "." + text;
Logger.Log("Appending old extension; writing image to " + outPath);
img.Write(outPath);
if (deleteSource && outPath != path)
{
Logger.Log("Deleting source file: " + path);
File.Delete(path);
Expand Down
4 changes: 2 additions & 2 deletions Code/UI/MainUIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static async void UpscalePreview(bool fullImage = false)
if (fullImage)
{
prevMode = ESRGAN.PreviewMode.FullImage;
if (!IOUtils.TryCopy(Program.lastFilename, Path.Combine(Paths.previewPath, "preview.png"), true)) return;
if (!IOUtils.TryCopy(Paths.tempImgPath, Path.Combine(Paths.previewPath, "preview.png"), true)) return;
}
else
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public static async void UpscalePreview(bool fullImage = false)

public static void SaveCurrentCutout()
{
UIHelpers.ReplaceImageAtSameScale(previewImg, IOUtils.GetImage(Program.lastFilename));
UIHelpers.ReplaceImageAtSameScale(previewImg, IOUtils.GetImage(Paths.tempImgPath));
string path = Path.Combine(Paths.previewPath, "preview.png");
Directory.CreateDirectory(Path.GetDirectoryName(path));
GetCurrentRegion().Save(path);
Expand Down

0 comments on commit 99e0245

Please sign in to comment.