Skip to content

Commit

Permalink
Move most static methods in FileLocator back to SIL.Core
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-polk committed Mar 14, 2018
1 parent 68f7396 commit 66f56ad
Show file tree
Hide file tree
Showing 14 changed files with 518 additions and 446 deletions.
6 changes: 3 additions & 3 deletions SIL.Archiving/ArchivingPrograms.cs
Expand Up @@ -26,10 +26,10 @@ public static string GetRampExeFileLocation()
const string rampFileExtension = ".ramp";

if (ArchivingDlgViewModel.IsMono)
exeFile = FileLocator.LocateInProgramFiles("RAMP", true);
exeFile = FileLocationUtilities.LocateInProgramFiles("RAMP", true);
else
exeFile = FileLocator.GetFromRegistryProgramThatOpensFileType(rampFileExtension) ??
FileLocator.LocateInProgramFiles("ramp.exe", true, "ramp");
FileLocationUtilities.LocateInProgramFiles("ramp.exe", true, "ramp");

// make sure the file exists
return !File.Exists(exeFile) ? null : new FileInfo(exeFile).FullName;
Expand All @@ -40,7 +40,7 @@ public static string GetArbilExeFileLocation()
{
var exeFile = ArchivingDlgViewModel.IsMono
? FindArbilJarFileMono()
: FileLocator.LocateInProgramFiles("arbil-stable.exe", true, "arbil");
: FileLocationUtilities.LocateInProgramFiles("arbil-stable.exe", true, "arbil");

// make sure the file exists
return !File.Exists(exeFile)
Expand Down
4 changes: 2 additions & 2 deletions SIL.Archiving/RampArchivingDlgViewModel.cs
Expand Up @@ -1409,9 +1409,9 @@ private static void BringToFrontMono()
{
// On mono this requires xdotool or wmctrl
string args = null;
if (!string.IsNullOrEmpty(FileLocator.LocateInProgramFiles("xdotool", true))) /* try to find xdotool first */
if (!string.IsNullOrEmpty(FileLocationUtilities.LocateInProgramFiles("xdotool", true))) /* try to find xdotool first */
args = "-c \"for pid in `xdotool search --name RAMP`; do xdotool windowactivate $pid; done\"";
else if (!string.IsNullOrEmpty(FileLocator.LocateInProgramFiles("wmctrl", true))) /* if xdotool is not installed, look for wmctrl */
else if (!string.IsNullOrEmpty(FileLocationUtilities.LocateInProgramFiles("wmctrl", true))) /* if xdotool is not installed, look for wmctrl */
args = "-c \"wmctrl -a RAMP\"";

if (string.IsNullOrEmpty(args)) return;
Expand Down
126 changes: 0 additions & 126 deletions SIL.Core.Desktop.Tests/IO/FileLocatorTests.cs
Expand Up @@ -13,43 +13,6 @@ namespace SIL.Tests.IO
[TestFixture]
public class FileLocatorTests
{
[Test]
public void GetFileDistributedWithApplication_MultipleParts_FindsCorrectly()
{
var path = FileLocator.GetFileDistributedWithApplication("DirectoryForTests", "SampleFileForTests.txt");
Assert.That(File.Exists(path));
}
[Test]
public void GetDirectoryDistributedWithApplication_MultipleParts_FindsCorrectly()
{
var path = FileLocator.GetDirectoryDistributedWithApplication("DirectoryForTests");
Assert.That(Directory.Exists(path));
}

[Test]
public void GetDirectoryDistributedWithApplication_WhenFails_ReportsAllTried()
{
try
{
FileLocator.GetDirectoryDistributedWithApplication("LookHere","ThisWillNotExist");
}
catch (ArgumentException ex)
{
Assert.That(ex.Message, Is.StringContaining(Path.Combine("LookHere", "ThisWillNotExist") ));
Assert.That(ex.Message, Is.StringContaining(FileLocator.DirectoryOfApplicationOrSolution));
Assert.That(ex.Message, Is.StringContaining("DistFiles"));
Assert.That(ex.Message, Is.StringContaining("src"));
}
}

[Test]
public void DirectoryOfApplicationOrSolution_OnDevMachine_FindsOutputDirectory()
{
var path = FileLocator.DirectoryOfTheApplicationExecutable;
Assert.That(Directory.Exists(path));
Assert.That(path.Contains("output"));
}

[Test]
public void LocateFile_ErrorMessageProvidedAndFileNoteFound_WouldShowErrorReport()
{
Expand Down Expand Up @@ -92,94 +55,5 @@ public void GetFromRegistryProgramThatOpensFileType_SendExtensionWithoutPeriod_R
{
Assert.IsNotNull(FileLocator.GetFromRegistryProgramThatOpensFileType("txt"));
}

[Test]
public void LocateInProgramFiles_SendInvalidProgramNoDeepSearch_ReturnsNull()
{
Assert.IsNull(FileLocator.LocateInProgramFiles("blah.exe", false));
}

// 12 SEP 2013, Phil Hopper: This test not valid on Mono.
[Test]
[Platform(Exclude="Unix")]
[Category("SkipOnTeamCity;KnownMonoIssue")]
public void LocateInProgramFiles_SendValidProgramNoDeepSearch_ReturnsNull()
{
Assert.IsNull(FileLocator.LocateInProgramFiles("msinfo32.exe", false));
}

[Test]
public void LocateInProgramFiles_SendValidProgramDeepSearch_ReturnsProgramPath()
{
var findFile = (Platform.IsMono ? "bash" : "msinfo32.exe");
Assert.IsNotNull(FileLocator.LocateInProgramFiles(findFile, true));
}

[Test]
public void LocateInProgramFiles_SendValidProgramDeepSearch_SubFolderSpecified_ReturnsProgramPath()
{
var findFile = (Platform.IsMono ? "bash" : "msinfo32.exe");

// this will work on Mono because it ignores the subFoldersToSearch parameter
Assert.IsNotNull(FileLocator.LocateInProgramFiles(findFile, true, "Common Files"));
}

[Test]
public void LocateInProgramFiles_SendInValidSubFolder_DoesNotThrow()
{
var findFile = (Platform.IsMono ? "bash" : "msinfo32.exe");
Assert.DoesNotThrow(() => FileLocator.LocateInProgramFiles(findFile, true, "!~@blah"));
}

//TODO: this could use lots more tests

[Test]
public void LocateExecutable_DistFiles()
{
Assert.That(FileLocator.LocateExecutable("DirectoryForTests", "SampleExecutable.exe"),
Is.StringEnding(string.Format("DistFiles{0}DirectoryForTests{0}SampleExecutable.exe",
Path.DirectorySeparatorChar)));
}

[Test]
[Platform(Exclude="Linux")]
public void LocateExecutable_PlatformSpecificInDistFiles_Windows()
{
Assert.That(FileLocator.LocateExecutable("DirectoryForTests", "dummy.exe"),
Is.StringEnding(string.Format("DistFiles{0}Windows{0}DirectoryForTests{0}dummy.exe",
Path.DirectorySeparatorChar)));
}

[Test]
[Platform(Include="Linux")]
public void LocateExecutable_PlatformSpecificInDistFiles_LinuxWithoutExtension()
{
Assert.That(FileLocator.LocateExecutable("DirectoryForTests", "dummy.exe"),
Is.StringEnding(string.Format("DistFiles{0}Linux{0}DirectoryForTests{0}dummy",
Path.DirectorySeparatorChar)));
}

[Test]
[Platform(Include="Linux")]
public void LocateExecutable_PlatformSpecificInDistFiles_Linux()
{
Assert.That(FileLocator.LocateExecutable("DirectoryForTests", "dummy2.exe"),
Is.StringEnding(string.Format("DistFiles{0}Linux{0}DirectoryForTests{0}dummy2.exe",
Path.DirectorySeparatorChar)));
}

[Test]
public void LocateExecutable_NonexistingFile()
{
Assert.That(FileLocator.LocateExecutable(false, "dummy", "__nonexisting.exe"), Is.Null);
}

[Test]
public void LocateExecutable_NonexistingFileThrows()
{
Assert.That(() => FileLocator.LocateExecutable("dummy", "__nonexisting.exe"),
Throws.Exception.TypeOf<ApplicationException>());
}

}
}

0 comments on commit 66f56ad

Please sign in to comment.