Skip to content

Commit

Permalink
Added more utils to GUI + some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Jul 20, 2020
1 parent a32a454 commit 051c15d
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 61 deletions.
Binary file modified .vs/MagickUtils/v16/.suo
Binary file not shown.
264 changes: 222 additions & 42 deletions Form1.Designer.cs

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,21 @@ private void remAlphaBlack_Click (object sender, EventArgs e)
{
OtherUtilsUI.RemTransparency(recursiveCbox.Checked, false);
}

private void delSmallImagesBtn_Click (object sender, EventArgs e)
{
int minSize = int.Parse(delSmallImagesSizeCombox.Text);
OtherUtilsUI.DelSmallImgsDir(recursiveCbox.Checked, minSize);
}

private void delFilesNotMatchingExtBtn_Click (object sender, EventArgs e)
{
OtherUtilsUI.DelNotMatchingWildcard(recursiveCbox.Checked);
}

private void groupNormalsBtn_Click (object sender, EventArgs e)
{
OtherUtilsUI.GroupNormalsWithTex(normalSuffixCombox.Text, diffSuffixCombox.Text, lowercaseCbox.Checked);
}
}
}
}
48 changes: 31 additions & 17 deletions OtherUtilsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Configuration;

namespace MagickUtils
{
Expand All @@ -18,34 +19,40 @@ public static void OtherUtilChooser (string ext)
Console.Write("Enter your command number: ");
string cmd = Console.ReadLine();


/*
if(int.Parse(cmd) == 1)
DelSmallImgsDir(ext);
if(int.Parse(cmd) == 2)
DelMissing(ext);
if(int.Parse(cmd) == 3)
DelNotMatchingWildcard(ext);
*/
}

static void DelNotMatchingWildcard (string ext)
public static void DelNotMatchingWildcard (bool recursive)
{

/*
string recursive = "n";
Console.Write("[Default: n] Recursive (include all subfolders)? (y/n): ");
string recursiveInput = Console.ReadLine();
if(!string.IsNullOrWhiteSpace(recursiveInput.Trim())) recursive = recursiveInput;
*/

DirectoryInfo d = new DirectoryInfo(Program.currentDir);
FileInfo[] whitelist;
FileInfo[] allFiles;

if(Program.IsTrue(recursive))
if(recursive)
{
allFiles = d.GetFiles("*.*", SearchOption.AllDirectories);
whitelist = d.GetFiles("*." + ext, SearchOption.AllDirectories);
whitelist = d.GetFiles("*." + Program.currentExt, SearchOption.AllDirectories);
}
else
{
allFiles = d.GetFiles("*.*", SearchOption.TopDirectoryOnly);
whitelist = d.GetFiles("*." + ext, SearchOption.TopDirectoryOnly);
whitelist = d.GetFiles("*." + Program.currentExt, SearchOption.TopDirectoryOnly);
}

List<string> whitelistedPaths = new List<string>();
Expand Down Expand Up @@ -77,27 +84,32 @@ public static void RemTransparency (bool recursive, bool whiteBg)
Program.PostProcessing();
}

static void DelSmallImgsDir (string ext)
public static void DelSmallImgsDir (bool recursive, int minAxisLength)
{
/*
string minAxisLength = "128";
Console.Write("[Default: 128] Set minimum length of shorter axis: ");
string minAxisLengthInput = Console.ReadLine();
if(!string.IsNullOrWhiteSpace(minAxisLengthInput.Trim())) minAxisLength = minAxisLengthInput;
*/

int counter = 1;
DirectoryInfo d = new DirectoryInfo(Program.currentDir);
FileInfo[] Files = d.GetFiles("*." + ext);
FileInfo[] Files = Program.GetFiles(Program.currentDir, Program.currentExt, recursive);
Program.Print("Checking " + Files.Length + " images...");
Program.PreProcessing();
foreach(FileInfo file in Files)
{
// Print("Checking Image " + counter + "/" + Files.Length);
Program.ShowProgress("", counter, Files.Length);
counter++;
OtherUtils.DeleteSmallImages(file.FullName, int.Parse(minAxisLength));
OtherUtils.DeleteSmallImages(file.FullName, minAxisLength);
}
Program.PostProcessing();
}

public static void GroupNormalsWithTex (string ext)
public static void GroupNormalsWithTex (string normalSuffixList, string diffuseSuffixList, bool lowercase)
{
/*
string setPrefix = "unnamed";
Console.Write("[Default: 'unnamed'] Suffix for this texture set (e.g. game name): ");
string setSuffixInput = Console.ReadLine();
Expand All @@ -111,21 +123,23 @@ public static void GroupNormalsWithTex (string ext)
string normalSuffix = "_n";
Console.Write("[Default: '_n'] Suffixes of normal map textures, comma-separated: ");
string normalSuffixInput = Console.ReadLine();
if(!string.IsNullOrWhiteSpace(normalSuffixInput.Trim())) normalSuffix = normalSuffixInput;

string[] nrmSuffixes = normalSuffix.Split(',');
if(!string.IsNullOrWhiteSpace(normalSuffixInput.Trim())) normalSuffix = normalSuffixInput
string albedoSuffix = "";
Console.Write("[Default: ''] Suffixes of albedo/base textures (can be empty for no suffix), comma-separated: ");
string albedoSuffixInput = Console.ReadLine();
if(!string.IsNullOrWhiteSpace(albedoSuffixInput.Trim())) albedoSuffix = albedoSuffixInput;
*/

string[] nrmSuffixes = normalSuffixList.Split(',');
string[] albSuffixes = diffuseSuffixList.Split(',');

string[] albSuffixes = albedoSuffix.Split(',');
string setPrefix = "tex";

OtherUtils.GroupNormalsWithTex(ext, nrmSuffixes, albSuffixes, setPrefix, Program.IsTrue(lowercase));
OtherUtils.GroupNormalsWithTex(Program.currentExt, nrmSuffixes, albSuffixes, setPrefix, lowercase);
}

public static void DelMissing (string ext)
public static void DelMissing ()
{
string checkDir = "";
Console.Write("Enter second directory to check for paired files: ");
Expand All @@ -139,7 +153,7 @@ public static void DelMissing (string ext)
if(!string.IsNullOrWhiteSpace(matchSizeInput.Trim())) matchSize = matchSizeInput;
*/

OtherUtils.RemoveMissingFiles(ext, checkDir);
OtherUtils.RemoveMissingFiles(Program.currentExt, checkDir);
}
}
}
4 changes: 3 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ static void PrintFilesInDir (string ext)

public static void ShowProgress (string text, int current, int amount)
{
Print("\n" + text + current + "/" + amount);

if(text.Trim().Length > 1)
Print("\n" + text + current + "/" + amount);
progBar.Value = (int)Math.Round((float)current / amount * 100);
}

Expand Down
Binary file modified bin/Debug/MagickUtils.exe
Binary file not shown.
Binary file modified bin/Debug/MagickUtils.pdb
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.csproj.GenerateResource.cache
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.exe
Binary file not shown.
Binary file modified obj/Debug/MagickUtils.pdb
Binary file not shown.

0 comments on commit 051c15d

Please sign in to comment.