Skip to content

Commit d5d9e7d

Browse files
committed
Split ProductUpgraderInfo into a shared and non-shared class
This will facilitate adding tests for the logic that the hooks projects do not depend on, as those projects do not support the PhysicalFileSystem abstraction.
1 parent 9ed3e39 commit d5d9e7d

4 files changed

Lines changed: 65 additions & 55 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using GVFS.Common.Tracing;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
6+
namespace GVFS.Common
7+
{
8+
public partial class ProductUpgraderInfo
9+
{
10+
public const string UpgradeDirectoryName = "GVFS.Upgrade";
11+
public const string LogDirectory = "Logs";
12+
public const string DownloadDirectory = "Downloads";
13+
public const string HighestAvailableVersionFileName = "HighestAvailableVersion";
14+
15+
private const string RootDirectory = UpgradeDirectoryName;
16+
17+
public static bool IsLocalUpgradeAvailable(ITracer tracer)
18+
{
19+
try
20+
{
21+
return File.Exists(GetHighestAvailableVersionFilePath());
22+
}
23+
catch (Exception ex) when (
24+
ex is IOException ||
25+
ex is UnauthorizedAccessException ||
26+
ex is NotSupportedException)
27+
{
28+
if (tracer != null)
29+
{
30+
tracer.RelatedError(
31+
CreateEventMetadata(ex),
32+
"Exception encountered when determining if an upgrade is available.");
33+
}
34+
}
35+
36+
return false;
37+
}
38+
39+
public static string GetHighestAvailableVersionFilePath()
40+
{
41+
return Path.Combine(GetUpgradesDirectoryPath(), HighestAvailableVersionFileName);
42+
}
43+
44+
public static string GetUpgradesDirectoryPath()
45+
{
46+
return Paths.GetServiceDataRoot(RootDirectory);
47+
}
48+
49+
private static EventMetadata CreateEventMetadata(Exception e)
50+
{
51+
EventMetadata metadata = new EventMetadata();
52+
if (e != null)
53+
{
54+
metadata.Add("Exception", e.ToString());
55+
}
56+
57+
return metadata;
58+
}
59+
}
60+
}

GVFS/GVFS.Common/ProductUpgraderInfo.cs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,8 @@
55

66
namespace GVFS.Common
77
{
8-
public class ProductUpgraderInfo
8+
public partial class ProductUpgraderInfo
99
{
10-
public const string UpgradeDirectoryName = "GVFS.Upgrade";
11-
public const string LogDirectory = "Logs";
12-
public const string DownloadDirectory = "Downloads";
13-
public const string HighestAvailableVersionFileName = "HighestAvailableVersion";
14-
15-
protected const string RootDirectory = UpgradeDirectoryName;
16-
17-
public static bool IsLocalUpgradeAvailable(ITracer tracer)
18-
{
19-
try
20-
{
21-
return File.Exists(GetHighestAvailableVersionFilePath());
22-
}
23-
catch (Exception ex) when (
24-
ex is IOException ||
25-
ex is UnauthorizedAccessException ||
26-
ex is NotSupportedException)
27-
{
28-
if (tracer != null)
29-
{
30-
tracer.RelatedError(
31-
CreateEventMetadata(ex),
32-
"Exception encountered when determining if an upgrade is available.");
33-
}
34-
}
35-
36-
return false;
37-
}
38-
3910
public static void RecordHighestAvailableVersion(Version highestAvailableVersion)
4011
{
4112
string highestAvailableVersionFile = GetHighestAvailableVersionFilePath();
@@ -58,11 +29,6 @@ public static string CurrentGVFSVersion()
5829
return ProcessHelper.GetCurrentProcessVersion();
5930
}
6031

61-
public static string GetUpgradesDirectoryPath()
62-
{
63-
return Paths.GetServiceDataRoot(RootDirectory);
64-
}
65-
6632
public static string GetLogDirectoryPath()
6733
{
6834
return Path.Combine(Paths.GetServiceDataRoot(RootDirectory), LogDirectory);
@@ -95,11 +61,6 @@ public static void DeleteAllInstallerDownloads(ITracer tracer = null)
9561
}
9662
}
9763

98-
public static string GetHighestAvailableVersionFilePath()
99-
{
100-
return Path.Combine(GetUpgradesDirectoryPath(), HighestAvailableVersionFileName);
101-
}
102-
10364
private static void RecursiveDelete(string path)
10465
{
10566
if (!Directory.Exists(path))
@@ -122,16 +83,5 @@ private static void RecursiveDelete(string path)
12283

12384
directory.Delete();
12485
}
125-
126-
private static EventMetadata CreateEventMetadata(Exception e)
127-
{
128-
EventMetadata metadata = new EventMetadata();
129-
if (e != null)
130-
{
131-
metadata.Add("Exception", e.ToString());
132-
}
133-
134-
return metadata;
135-
}
13686
}
13787
}

GVFS/GVFS.Hooks/GVFS.Hooks.Mac.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<Compile Include="..\GVFS.Common\ProcessResult.cs">
7878
<Link>Common\ProcessResult.cs</Link>
7979
</Compile>
80-
<Compile Include="..\GVFS.Common\ProductUpgraderInfo.cs" Link="Common\ProductUpgraderInfo.cs" />
80+
<Compile Include="..\GVFS.Common\ProductUpgraderInfo.Shared.cs" Link="Common\ProductUpgraderInfo.Shared.cs" />
8181
<Compile Include="..\GVFS.Common\Tracing\EventLevel.cs">
8282
<Link>Common\Tracing\EventLevel.cs</Link>
8383
</Compile>

GVFS/GVFS.Hooks/GVFS.Hooks.Windows.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
<Compile Include="..\GVFS.Common\ProcessResult.cs">
9595
<Link>Common\ProcessResult.cs</Link>
9696
</Compile>
97-
<Compile Include="..\GVFS.Common\ProductUpgraderInfo.cs">
98-
<Link>Common\ProductUpgraderInfo.cs</Link>
97+
<Compile Include="..\GVFS.Common\ProductUpgraderInfo.Shared.cs">
98+
<Link>Common\ProductUpgraderInfo.Shared.cs</Link>
9999
</Compile>
100100
<Compile Include="..\GVFS.Common\Tracing\EventLevel.cs">
101101
<Link>Common\Tracing\EventLevel.cs</Link>
@@ -139,4 +139,4 @@
139139
<Target Name="AfterBuild">
140140
</Target>
141141
-->
142-
</Project>
142+
</Project>

0 commit comments

Comments
 (0)