Skip to content

Commit

Permalink
fix: using relative path to specify the msi file location would cause…
Browse files Browse the repository at this point in the history
… nothing to be extracted

fixes #97
  • Loading branch information
mega5800 authored Jul 17, 2024
1 parent 3d985b5 commit 82d6669
Show file tree
Hide file tree
Showing 5 changed files with 640 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/LessMsi.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ public static int Main(string[] args)
/// /// <param name="extractionMode">Enum value for files extraction without folder structure</param>
public static void DoExtraction(string msiFileName, string outDirName, List<string> filesToExtract, ExtractionMode extractionMode)
{
msiFileName = EnsureAbsolutePath(msiFileName);

if (string.IsNullOrEmpty(outDirName))
{
outDirName = Path.GetFileNameWithoutExtension(msiFileName);
}

EnsureFileRooted(ref msiFileName);
EnsureFileRooted(ref outDirName);
msiFileName = EnsureFileRooted(msiFileName);
outDirName = EnsureFileRooted(outDirName);

var msiFile = new LessIO.Path(msiFileName);

Expand Down Expand Up @@ -186,12 +190,24 @@ private static void PrintProgress(IAsyncResult result)
Console.WriteLine(string.Format("{0}/{1}\t{2}", progress.FilesExtractedSoFar + 1, progress.TotalFileCount, progress.CurrentFileName));
}

private static void EnsureFileRooted(ref string sFileName)
private static string EnsureFileRooted(string fileName)
{
if (Path.IsPathRooted(fileName))
{
return fileName;
}

return Path.Combine(Directory.GetCurrentDirectory(), fileName);
}

private static string EnsureAbsolutePath(string filePath)
{
if (!Path.IsPathRooted(sFileName))
if (Path.IsPathRooted(filePath))
{
sFileName = Path.Combine(Directory.GetCurrentDirectory(), sFileName);
return filePath;
}

return Path.GetFullPath(filePath);
}
}
}
22 changes: 22 additions & 0 deletions src/Lessmsi.Tests/CommandLineExtractTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public void Extract1Arg()
TestExtraction(commandLine, GetTestName(), "NUnit-2.5.2.9222", false);
}

[Fact]
public void Extract1ArgRelativePath()
{
var commandLine = "x .\\TestFiles\\MsiInput\\NUnit-2.5.2.9222.msi";
// setting "NUnit-2.5.2.9222" as actualEntriesOutputDir value, since no other output dir specified in command line text
TestExtraction(commandLine, GetTestName(), "NUnit-2.5.2.9222", false);
}

[Fact]
public void FlatOverwriteExtract1Arg()
{
Expand All @@ -39,6 +47,13 @@ public void Extract2Args()
TestExtraction(commandLine, GetTestName(), "Ex2Args", false);
}

[Fact]
public void Extract2ArgsRelativePath()
{
var commandLine = "x .\\TestFiles\\MsiInput\\NUnit-2.5.2.9222.msi Extract2ArgsRelativePath\\";
TestExtraction(commandLine, GetTestName(), "Extract2ArgsRelativePath", false);
}

[Fact]
public void FlatOverwriteExtract2Args()
{
Expand All @@ -60,6 +75,13 @@ public void Extract3Args()
TestExtraction(commandLine, GetTestName(), "Ex3", false);
}

[Fact]
public void Extract3ArgsRelativePath()
{
var commandLine = "x .\\TestFiles\\MsiInput\\NUnit-2.5.2.9222.msi Extract3ArgsRelativePath\\ \"cs-money.build\" \"requiresMTA.html\"";
TestExtraction(commandLine, GetTestName(), "Extract3ArgsRelativePath", false);
}

[Fact]
public void FlatOverwriteExtract3Args()
{
Expand Down
Loading

0 comments on commit 82d6669

Please sign in to comment.