-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDiffInfo.php
More file actions
59 lines (51 loc) · 1.72 KB
/
Copy pathDiffInfo.php
File metadata and controls
59 lines (51 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace ApprovalTests\Reporters;
class DiffInfo
{
public $diffProgram;
public $parameters;
public $fileExtensions;
public function __construct($diffProgram, array $fileExtensions, $parameters = null)
{
$this->diffProgram = self::resolveWindowsPath($diffProgram);
$this->parameters = $parameters ?: GenericDiffReporter::$STANDARD_ARGUMENTS;
$this->fileExtensions = $fileExtensions;
}
private static function resolveWindowsPath($diffProgram)
{
$tag = "{ProgramFiles}";
$startsWith = substr($diffProgram, 0, strlen($tag)) === $tag;
if ($startsWith) {
$diffProgram = self::getPathInProgramFilesX86(substr($diffProgram, strlen($tag)));
}
return $diffProgram;
}
private static function getPathInProgramFilesX86($path)
{
$paths = self::getProgramFilesPaths();
return self::getFirstWorking($path, $paths, "C:\\Program Files\\");
}
public static function getFirstWorking($path, array $paths, $ifNotFoundDefault)
{
$fullPath = $ifNotFoundDefault . $path;
foreach ($paths as $p) {
$fullPath = $p . DIRECTORY_SEPARATOR . $path;
if (file_exists($fullPath)) {
break;
}
}
return $fullPath;
}
public static function getProgramFilesPaths()
{
$paths = [
getenv("ProgramFiles(x86)"),
getenv("ProgramFiles"),
getenv("ProgramW6432"),
// Programs like Beyond Compare 4 that support per-user installation
// will likely install themselves here.
getenv("LocalAppData"),
];
return array_unique(array_filter($paths));
}
}