Skip to content

Commit

Permalink
Single file as input
Browse files Browse the repository at this point in the history
- moved total time from TextureExtractor to ScanBase.
- small changes.
  • Loading branch information
Venomalia committed Sep 26, 2022
1 parent d05be24 commit 4c8980f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 52 deletions.
2 changes: 1 addition & 1 deletion TextureExtraction tool/Data/Cutter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void Scan(FileInfo file)
{
Stream stream = new FileStream(file.FullName, FileMode.Open);
FormatInfo FFormat = GetFormatTypee(stream, file.Extension);
string subdirectory = GetDirectoryWithoutExtension(file.FullName.Replace(ScanDirectory + Path.DirectorySeparatorChar, ""));
string subdirectory = GetDirectoryWithoutExtension(file.FullName.Replace(ScanPath + Path.DirectorySeparatorChar, ""));

#if !DEBUG
try
Expand Down
2 changes: 1 addition & 1 deletion TextureExtraction tool/Data/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void WriteHeader()
Flush();
}

public void WriteFoot(TextureExtractor.ExtractorResult result)
public void WriteFoot(ScanBase.Results result)
{
WriteLine("".PadLeft(64, '-'));
WriteLine($"~END {DateTime.Now}");
Expand Down
43 changes: 37 additions & 6 deletions TextureExtraction tool/Data/ScanBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace DolphinTextureExtraction_tool
{
public abstract class ScanBase
{
protected readonly string ScanDirectory;
protected readonly string ScanPath;

protected readonly string SaveDirectory;

Expand Down Expand Up @@ -114,6 +114,11 @@ internal void ProgressUpdate(Results result)

public class Results
{
/// <summary>
/// the time the scan process has taken
/// </summary>
public TimeSpan TotalTime { get; internal set; }

/// <summary>
/// count of all files to be searched.
/// </summary>
Expand All @@ -138,26 +143,53 @@ public class Results
/// Full path to the log file.
/// </summary>
public string LogFullPath { get; internal set; }

public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Scan time: {TotalTime.TotalSeconds:.000}s");
return sb.ToString();
}
}

protected ScanBase(string scanDirectory, string saveDirectory, Options options = null)
{
Option = options ?? new Options();
if (Option.DryRun)
saveDirectory = StringEx.ExePath;
ScanDirectory = scanDirectory;
ScanPath = scanDirectory;
SaveDirectory = saveDirectory;
Directory.CreateDirectory(SaveDirectory);
Log = new ScanLogger(SaveDirectory);
Events.NotificationEvent = Log.WriteNotification;
Result.LogFullPath = Log.FullPath;
}

public Results StartScan()
public virtual Results StartScan()
{
Scan(new DirectoryInfo(ScanDirectory));
Log.Flush();
DateTime starttime = DateTime.Now;

if (Directory.Exists(ScanPath))
{
Scan(new DirectoryInfo(ScanPath));
}
else if (File.Exists(ScanPath))
{
var file = new FileInfo(ScanPath);
Result.Worke = 1;
Result.WorkeLength = file.Length;
Scan(file);
}
else
{
throw new ArgumentException($"{ScanPath}: does not exist!");
}

Result.TotalTime = DateTime.Now.Subtract(starttime);

Log.WriteFoot(Result);
Log.Dispose();
GC.Collect();
return Result;
}

Expand All @@ -179,7 +211,6 @@ protected void Scan(DirectoryInfo directory)
}
Option.ProgressUpdate(Result);
});
GC.Collect();
}

private void ScanInitialize(DirectoryInfo directory, List<FileInfo> fileInfos)
Expand Down
12 changes: 2 additions & 10 deletions TextureExtraction tool/Data/TextureExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public ExtractorOptions()

public class ExtractorResult : Results
{
public TimeSpan TotalTime { get; internal set; }

public int MinExtractionRate => MathEx.RoundToInt(100d / (ExtractedSize + SkippedSize + UnsupportedSize) * ExtractedSize);

public int MaxExtractionRate => Extracted > 150 ? MathEx.RoundToInt(100d / (ExtractedSize + SkippedSize / (Extracted / 150) + UnsupportedSize) * ExtractedSize) : MinExtractionRate;
Expand Down Expand Up @@ -156,13 +154,7 @@ public static int ThreadIndex
// Reset Thread Indicies, no longer guaranteed to be the same threads as before
ThreadIndices.Clear();

DateTime starttime = DateTime.Now;

Scan(new DirectoryInfo(ScanDirectory));

Result.TotalTime = DateTime.Now.Subtract(starttime);
Log.WriteFoot(Result);
Log.Dispose();
base.StartScan();

if (((ExtractorOptions)Option).Cleanup)
{
Expand Down Expand Up @@ -191,7 +183,7 @@ protected override void Scan(FileInfo file)
Stream stream = new FileStream(file.FullName, FileMode.Open);
FormatInfo FFormat = GetFormatTypee(stream, file.Extension);

string subdirectory = GetDirectoryWithoutExtension(file.FullName.Replace(ScanDirectory + Path.DirectorySeparatorChar, ""));
string subdirectory = GetDirectoryWithoutExtension(file.FullName.Replace(ScanPath + Path.DirectorySeparatorChar, ""));

#if !DEBUG
try
Expand Down
2 changes: 1 addition & 1 deletion TextureExtraction tool/Data/Unpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override void Scan(FileInfo file)
{
Stream stream = new FileStream(file.FullName, FileMode.Open);
FormatInfo FFormat = GetFormatTypee(stream, file.Extension);
string subdirectory = GetDirectoryWithoutExtension(file.FullName.Replace(ScanDirectory + Path.DirectorySeparatorChar, ""));
string subdirectory = GetDirectoryWithoutExtension(file.FullName.Replace(ScanPath + Path.DirectorySeparatorChar, ""));

#if !DEBUG
try
Expand Down
62 changes: 31 additions & 31 deletions TextureExtraction tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DolphinTextureExtraction_tool
{
partial class Program
{
static string InputDirectory;
static string InputPath;

static string OutputDirectory;

Expand Down Expand Up @@ -102,39 +102,39 @@ static void Main(string[] args)
//Input Path
Console.WriteLine();
Console.WriteLine("Input Path:");
Console.WriteLine("Specify a directory from which the textures should be extracted.");
Console.WriteLine("Specify a directory or a file to be extracted.");
do
{
InputDirectory = Console.ReadLine().Trim('"');
InputPath = Console.ReadLine().Trim('"');

if (!Directory.Exists(InputDirectory))
if (!Directory.Exists(InputPath) && !File.Exists(InputPath))
{
ConsoleEx.WriteLineColoured("The directory could not be found!", ConsoleColor.Red);
ConsoleEx.WriteLineColoured("The directory or file could not be found!", ConsoleColor.Red);
}
} while (!Directory.Exists(InputDirectory));
} while (!Directory.Exists(InputPath) && !File.Exists(InputPath));

//Output Path
Console.WriteLine();
Console.WriteLine("Output Path:");
Console.WriteLine("Specify a directory where the textures should be saved.");
Console.WriteLine($"Or use default \t\"{GetGenOutputPath(InputDirectory)}\"");
Console.WriteLine("Specify an output directory where the extra files will be saved.");
Console.WriteLine($"Or use default \t\"{GetGenOutputPath(InputPath)}\"");
do
{
OutputDirectory = Console.ReadLine().Trim('"');
if (OutputDirectory == "")
{
OutputDirectory = GetGenOutputPath(InputDirectory);
OutputDirectory = GetGenOutputPath(InputPath);
}
if (!PathIsValid(OutputDirectory))
{
ConsoleEx.WriteLineColoured("Path is invalid!", ConsoleColor.Red);
}
if (OutputDirectory == InputDirectory)
if (OutputDirectory == InputPath)
{
ConsoleEx.WriteLineColoured("Output Directory and Input Directory cannot be the same!", ConsoleColor.Red);
ConsoleEx.WriteLineColoured("Output Directory and Input Path cannot be the same!", ConsoleColor.Red);
}

} while (!PathIsValid(OutputDirectory) || OutputDirectory == InputDirectory);
} while (!PathIsValid(OutputDirectory) || OutputDirectory == InputPath);



Expand Down Expand Up @@ -171,7 +171,7 @@ static void Main(string[] args)

//Inputs correct?
Console.WriteLine();
Console.WriteLine($"Input Path: \"{InputDirectory}\"");
Console.WriteLine($"Input Path: \"{InputPath}\"");
Console.WriteLine($"Output Path: \"{OutputDirectory}\"");
if (Mode == Modes.Extract)
PrintOptions(options);
Expand All @@ -185,18 +185,18 @@ static void Main(string[] args)
switch (Mode)
{
case Modes.Extract:
Console.WriteLine($"Search and extract textures from {InputDirectory}");
Console.WriteLine($"Search and extract textures from {InputPath}");
Console.WriteLine("This may take a few seconds...");
Console.WriteLine();
var result = TextureExtractor.StartScan(InputDirectory, OutputDirectory, options);
var result = TextureExtractor.StartScan(InputPath, OutputDirectory, options);
Console.WriteLine();
PrintResult(result);
break;
case Modes.Unpacks:
Console.WriteLine($"Unpacks all files from {InputDirectory}");
Console.WriteLine($"Unpacks all files from {InputPath}");
Console.WriteLine("This may take a few seconds...");
Console.WriteLine();
Unpack.StartScan(InputDirectory, OutputDirectory, options);
Unpack.StartScan(InputPath, OutputDirectory, options);
Console.WriteLine();
Console.WriteLine("Done.");
break;
Expand Down Expand Up @@ -238,7 +238,7 @@ static void Main(string[] args)
}
}

Cutter.StartScan(InputDirectory, OutputDirectory, pattern, options);
Cutter.StartScan(InputPath, OutputDirectory, pattern, options);
Console.WriteLine();
Console.WriteLine("completed.");
#endregion
Expand All @@ -250,7 +250,7 @@ static void Main(string[] args)
if (p <= 0)
goto default;

Unpack.StartScan(InputDirectory, OutputDirectory, options);
Unpack.StartScan(InputPath, OutputDirectory, options);
Console.WriteLine();
Console.WriteLine("completed.");
//PrintResult(result);
Expand Down Expand Up @@ -322,7 +322,7 @@ static void Main(string[] args)
case "-t":
if (!int.TryParse(args[++i], out int parse))
{
Console.Error.WriteLine($"Wrong syntax: \"{args[i-1]} {args[i]}\" Task needs a second parameter.");
Console.Error.WriteLine($"Wrong syntax: \"{args[i - 1]} {args[i]}\" Task needs a second parameter.");
Console.WriteLine("use h for help");
Environment.Exit(-2);
break;
Expand All @@ -332,7 +332,7 @@ static void Main(string[] args)
}
}
}
var result = TextureExtractor.StartScan(InputDirectory, OutputDirectory, options);
var result = TextureExtractor.StartScan(InputPath, OutputDirectory, options);

Console.WriteLine();

Expand All @@ -348,9 +348,9 @@ static void Main(string[] args)
default:
if (Directory.Exists(args[0]))
{
InputDirectory = args[0];
OutputDirectory = GetGenOutputPath(InputDirectory);
TextureExtractor.StartScan(InputDirectory, OutputDirectory);
InputPath = args[0];
OutputDirectory = GetGenOutputPath(InputPath);
TextureExtractor.StartScan(InputPath, OutputDirectory);
}
Console.Error.WriteLine("Wrong syntax.");
Console.WriteLine("use h for help");
Expand All @@ -366,21 +366,21 @@ private static int GetPahts(string[] args)
if (args.Length < 2)
return -1;

InputDirectory = args[1];
InputPath = args[1];
if (args.Length >= 3)
OutputDirectory = args[2];
else
OutputDirectory = GetGenOutputPath(InputDirectory);
OutputDirectory = GetGenOutputPath(InputPath);

if (!Directory.Exists(InputDirectory))
if (!Directory.Exists(InputPath) && !File.Exists(InputPath))
{
Console.WriteLine("The directory could not be found!");
Console.WriteLine(InputDirectory);
Console.WriteLine(InputPath);
return -1;
}
if (!PathIsValid(OutputDirectory))
{
OutputDirectory = GetGenOutputPath(InputDirectory);
OutputDirectory = GetGenOutputPath(InputPath);
return 2;
}
return 3;
Expand Down Expand Up @@ -539,8 +539,8 @@ static void ProgressTitleUpdate(ScanBase.Results result)
{ }
}

//change only with caution! this function is required by Custom Texture Tool https://forums.dolphin-emu.org/Thread-custom-texture-tool-ps-v50-1
static void TextureUpdate(JUTTexture.TexEntry texture,Results result , in string subdirectory)
//change only with caution! this function is required by the Custom Texture Tool https://forums.dolphin-emu.org/Thread-custom-texture-tool-ps-v50-1
static void TextureUpdate(JUTTexture.TexEntry texture, Results result, in string subdirectory)
{
double ProgressPercentage = result.ProgressLength / result.WorkeLength * 100;
Console.WriteLine($"Prog:{Math.Round(ProgressPercentage, 2)}% Extract:{Path.Combine(subdirectory, texture.GetDolphinTextureHash()) + ".png"} mips:{texture.Count - 1} LODBias:{texture.LODBias} MinLOD:{texture.MinLOD} MaxLOD:{texture.MaxLOD}");
Expand Down
4 changes: 2 additions & 2 deletions TextureExtraction tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0.7")]
[assembly: AssemblyFileVersion("0.9.0.7")]
[assembly: AssemblyVersion("0.9.0.9")]
[assembly: AssemblyFileVersion("0.9.0.9")]

0 comments on commit 4c8980f

Please sign in to comment.