Skip to content

Commit

Permalink
Fixed a crash happening when going through the original behaviour
Browse files Browse the repository at this point in the history
The base extraction path variable wasn't set in this case...
  • Loading branch information
Mateos81 committed Nov 12, 2020
1 parent f66e8e1 commit f04b67a
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions KFTempArchiveExtractor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Program
/// <param name="args">Application arguments.</param>
public static void Main(string[] args)
{
Console.WriteLine("KF Temp Archive Extractor 1.2");

if (args.Length != 0)
{
OriginalBehaviour(args);
Expand All @@ -53,16 +55,7 @@ public static void Main(string[] args)
return;
}

// If needed, create the sub-folder in application's path
_baseExtractionPath =
Path.Combine(
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
"KF Archive Files");

if (!Directory.Exists(_baseExtractionPath))
{
Directory.CreateDirectory(_baseExtractionPath);
}
SetAndCreateBaseExtractionPath();

// Process the files
foreach (FileInfo archiveFile in archiveFiles)
Expand All @@ -77,18 +70,6 @@ public static void Main(string[] args)

#region Methods

/// <summary>
/// Retrieves KF installation directory from the system registry.
/// </summary>
/// <returns>The path to the local KF installation directory.</returns>
private static string GetKFInstallDir()
{
return Microsoft.Win32.Registry.GetValue(
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1250",
"InstallLocation",
null).ToString();
}

/// <summary>
/// Original behaviour: drag and drop one file onto the executable.
/// One difference though: the <see cref="Process(FileInfo)"/> function will create a sub-folder per Archive file.
Expand All @@ -102,14 +83,45 @@ private static void OriginalBehaviour(string[] args)
return;
}

FileInfo archiveFile = new FileInfo(args[0]);
SetAndCreateBaseExtractionPath();

FileInfo archiveFile = new FileInfo(args[0]);
if (!Process(archiveFile))
{
Console.WriteLine($"File {archiveFile.Name} incorrectly processed.");
}
}

/// <summary>
/// Sets the base extraction path, and creates it if it doesn't already exists.
/// </summary>
private static void SetAndCreateBaseExtractionPath()
{
// If needed, create the sub-folder in application's path
_baseExtractionPath =
Path.Combine(
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
"KF Archive Files");

if (!Directory.Exists(_baseExtractionPath))
{
Console.WriteLine("Creating base extraction directory...");
Directory.CreateDirectory(_baseExtractionPath);
}
}

/// <summary>
/// Retrieves KF installation directory from the system registry.
/// </summary>
/// <returns>The path to the local KF installation directory.</returns>
private static string GetKFInstallDir()
{
return Microsoft.Win32.Registry.GetValue(
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1250",
"InstallLocation",
null).ToString();
}

/// <summary>
/// Processes a KF Archive file.
/// </summary>
Expand Down Expand Up @@ -238,4 +250,4 @@ private static void ProcessOverPausing()

#endregion Methods
}
}
}

0 comments on commit f04b67a

Please sign in to comment.