Skip to content

Commit 0b73b96

Browse files
authored
Merge 0.3.1 changes (#79)
* Update command would no longer conflict with existing paths (#74) * Update command would no longer conflict with existing paths * Added new unit test * Display correct warning/error, backup create (#76) * Display correct warning/error, backup create * Added new unit test * Fixed a bug where it returned a prerelease when the flag was not run (#73) * Fixed a bug where it returned a prerelease when the flag was not run * Fix null return because of incorrect if-statement * Log creation does not bug anymore (#80) * Log creation does not bug anymore * Updated error message in WinPath * Add backwards compatibility support (update cmd) * Fix incorrect display issues. (#83) * backup list command now balances table * Fix spelling mistake * Added new unit test * Fix mistakes * Update changelog and version
1 parent ced94f2 commit 0b73b96

File tree

9 files changed

+198
-54
lines changed

9 files changed

+198
-54
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [v0.3.1](https://github.com/ANF-Studios/WinPath/releases/tag/0.3.1)
4+
* Minor fix in update command; conflicting paths (#49).
5+
* List command should display the table of backups without inconsistencies (#52).
6+
* `WinPath.Updater` (manages updates) will now log errors correctly (#54).
7+
* Running `winpath backup create` will now give the correct error instead of "Something went wrong!" (#56).
8+
* Minor bug fix when prerelease flag was not run (#72).
9+
* [Other/Non-bug fix change] `WinPath.Updater` now has backwards compatibility support with v0.2.0 and v0.3.0 (#78).
10+
311
## [v0.3.0](https://github.com/ANF-Studios/WinPath/releases/tag/0.3.0)
412
* WinPath.Library.UserPath now targets async tasks instead of sync voids.
513
* Changed download directory (of update command) to `%TEMP%\WinPath\download` from `%APPDATA%\WinPath\temp\download`.

WinPath.Tests/BackupCommandTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ public void CreateBackupClass()
152152
output.WriteLine(backup.ToString());
153153
}
154154

155+
[Fact]
156+
[SupportedOSPlatform("windows")]
157+
public void CreateBackupWithoutUserAndSystemFlags()
158+
{
159+
Program.Main(new string[]
160+
{
161+
"backup",
162+
"create"
163+
});
164+
}
165+
155166
[Fact]
156167
[SupportedOSPlatform("windows")]
157168
public void CreateUserBackup()
@@ -213,6 +224,18 @@ public void CreateUserAndSystemBackup()
213224
}
214225

215226
[Fact]
227+
[SupportedOSPlatform("windows")]
228+
public void CreateNeitherUserOrSystemBackup()
229+
{
230+
Program.Main(
231+
new string[]
232+
{
233+
"backup",
234+
"create"
235+
}
236+
);
237+
}
238+
216239
[SupportedOSPlatform("windows")]
217240
public void CreateUserBackupInASpecifiedDirectory()
218241
{

WinPath.Tests/UpdateTests.cs

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ public void LatestPrereleaseHasAssets()
7878
{
7979
string architecture = Update.GetArchitecture(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture).ToLower();
8080
Update update = new Update(true, false, (architecture == "x64" || architecture == "x86"));
81-
81+
8282
var releases = update.GetReleases();
8383
var release = update.FilterRelease(releases);
8484

8585
output.WriteLine(
86-
"Release name: " + release.ReleaseName + "\n"
87-
+ "Release tag: " + release.TagName + "\n"
88-
+ "Is Prerelease: " + release.IsPrerelease
86+
"Release name: " + release?.ReleaseName + "\n"
87+
+ "Release tag: " + release?.TagName + "\n"
88+
+ "Is Prerelease: " + release?.IsPrerelease
8989
);
9090

91-
Assert.True(release.IsPrerelease);
92-
Assert.NotEmpty(release.Assets);
91+
Assert.True(release?.IsPrerelease);
92+
Assert.NotEmpty(release?.Assets);
9393
}
9494

9595
[Fact]
@@ -102,13 +102,13 @@ public void FilteredReleaseIsNotPrerelease()
102102
var release = update.FilterRelease(releases);
103103

104104
output.WriteLine(
105-
"Release name: " + release.ReleaseName + "\n"
106-
+ "Release tag: " + release.TagName + "\n"
107-
+ "Is Prerelease: " + release.IsPrerelease
105+
"Release name: " + release?.ReleaseName + "\n"
106+
+ "Release tag: " + release?.TagName + "\n"
107+
+ "Is Prerelease: " + release?.IsPrerelease
108108
);
109109

110110
if (!releases.Where(release => release.IsPrerelease == true).Any()) // If all releases are NOT prereleases.
111-
Assert.False(release.IsPrerelease); // Then check if this one isn't a prerelease.
111+
Assert.False(release?.IsPrerelease); // Then check if this one isn't a prerelease.
112112
else Assert.True(true); // Else simply pass.
113113
}
114114

@@ -117,20 +117,20 @@ public void LatestReleaseHasAssets()
117117
{
118118
string architecture = Update.GetArchitecture(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture).ToLower();
119119
Update update = new Update(true, false, (architecture == "x64" || architecture == "x86"));
120-
120+
121121
var releases = update.GetReleases();
122122
var release = update.FilterRelease(releases);
123123

124124
output.WriteLine(
125-
"Release name: " + release.ReleaseName + "\n"
126-
+ "Release tag: " + release.TagName + "\n"
127-
+ "Is Prerelease: " + release.IsPrerelease
125+
"Release name: " + release?.ReleaseName + "\n"
126+
+ "Release tag: " + release?.TagName + "\n"
127+
+ "Is Prerelease: " + release?.IsPrerelease
128128
);
129129

130-
if (!release.ReleaseName.Contains("Test release")) // If the release is not a test release,
131-
Assert.NotEmpty(release.Assets); // check if it's not empty.
132-
else //
133-
Assert.True(true); // Else simply pass.
130+
if (!(bool)release?.ReleaseName.Contains("Test release")) // If the release is not a test release,
131+
Assert.NotEmpty(release?.Assets); // check if it's not empty.
132+
else //
133+
Assert.True(true); // Else simply pass.
134134
}
135135

136136
[Fact]
@@ -141,11 +141,49 @@ public void GetAssetForProcessSuccessfully()
141141

142142
var releases = update.GetReleases();
143143
var release = update.FilterRelease(releases);
144-
var assetForProcess = (Asset?)update.GetAssetForProcess(release);
144+
var assetForProcess = (Asset?)update.GetAssetForProcess((Release)release);
145145

146146
output.WriteLine("Executable name: " + assetForProcess?.ExecutableName ?? "None");
147147

148148
Assert.True(assetForProcess is not null);
149149
}
150+
151+
// TODO: Remove starting from v1.0.0.
152+
/// <summary>
153+
/// Runs the update command with prerelease flag.
154+
/// </summary>
155+
/// <remarks>
156+
/// This command runs <c>winpath update</c>, simply this command.
157+
/// This is used to test whether it picks a prerelease or not
158+
/// since the prerelease flag is not used.
159+
/// </remarks>
160+
[Fact]
161+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
162+
public void GetNullRelease()
163+
{
164+
Program.Main(
165+
new string[] { "update" }
166+
);
167+
}
168+
169+
[Fact]
170+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
171+
public void UpdatePathWithoutEndingSemicolon()
172+
{
173+
string initialPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User);
174+
if (initialPath.EndsWith(";"))
175+
initialPath = initialPath.TrimEnd(';');
176+
177+
Environment.SetEnvironmentVariable("Path", initialPath, EnvironmentVariableTarget.User);
178+
179+
Program.Main(
180+
new string[]
181+
{
182+
"update",
183+
"--prerelease",
184+
"-y"
185+
}
186+
);
187+
}
150188
}
151189
}

WinPath.Updater/Program.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
using System;
22
using System.IO;
3+
using System.Diagnostics;
34

45
namespace WinPath.Updater
56
{
67
class Program
78
{
8-
private static readonly string executableDirectory = $"{Path.GetTempPath()}WinPath\\download\\WinPath.exe";
9+
private static string executableDirectory = Path.Combine(
10+
Path.GetTempPath(),
11+
"WinPath\\download\\WinPath.exe");
12+
private static readonly string logDirectory = Path.Combine(
13+
Path.GetTempPath(),
14+
"WinPath\\logs\\log.txt");
915
private const string launchingFromWinPath = "launching_from_winpath";
16+
private const string errorMessage = "Could not install WinPath because of an error: ";
1017

1118
public static void Main(string[] args)
1219
{
13-
if (args.Length < 1) // To prevent crashing if args is 0 in the next if-statement.
14-
return;
15-
if (args[0] != launchingFromWinPath)
16-
return;
1720
Console.Title = AppDomain.CurrentDomain.FriendlyName;
21+
string currentVersion = GetInstalledWinPathVersion();
22+
23+
if (currentVersion is null)
24+
Environment.Exit(-1);
25+
26+
if (currentVersion == "0.2.0") // Backwards compatibility support.
27+
executableDirectory = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\WinPath\\temp\\download\\WinPath.exe";
28+
29+
if (int.Parse(currentVersion[2].ToString()) > 2)
30+
{
31+
if (args.Length < 1) // To prevent crashing if args is 0 in the next if-statement.
32+
return;
33+
if (args[0] != launchingFromWinPath)
34+
return;
35+
}
1836
try
1937
{
2038
if (Environment.Is64BitOperatingSystem)
@@ -58,10 +76,34 @@ public static void Main(string[] args)
5876
{
5977
Console.WriteLine("Could not install WinPath: " + exception.Message);
6078
//Console.ReadKey();
61-
File.WriteAllText(Directory.GetCurrentDirectory() + "log.txt", "Could not install WinPath: " + exception.Message);
79+
Directory.CreateDirectory(logDirectory.Replace("log.txt", string.Empty));
80+
File.AppendAllText(
81+
logDirectory,
82+
DateTime.Today.ToLongDateString()
83+
+ "\n"
84+
+ errorMessage
85+
+ exception.Message
86+
+ "\n"
87+
+ "Please report this to the developer."
88+
+ "\n"
89+
);
90+
Console.WriteLine("Exception logged at " + logDirectory);
6291
Environment.ExitCode = 1;
6392
}
6493
Environment.Exit(Environment.ExitCode);
6594
}
95+
96+
public static string GetInstalledWinPathVersion()
97+
{
98+
FileVersionInfo winPathVersion = null;
99+
string installationPath = Environment.Is64BitOperatingSystem
100+
? "C:\\Program Files\\WinPath\\WinPath.exe"
101+
: "C:\\Program Files (x86)\\WinPath\\WinPath.exe";
102+
if (File.Exists(installationPath))
103+
winPathVersion = FileVersionInfo.GetVersionInfo(installationPath);
104+
else
105+
return null;
106+
return $"{winPathVersion.FileMajorPart}.{winPathVersion.FileMinorPart}.{winPathVersion.FileBuildPart}";
107+
}
66108
}
67109
}

WinPath.Updater/WinPath.Updater.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0</TargetFramework>
66
<PublishReadyToRun>true</PublishReadyToRun>
7-
<Version>0.3.0</Version>
7+
<Version>0.3.1</Version>
88
<Authors>ANF-Studios</Authors>
99
<Description>WinPath's Update manager!</Description>
1010

WinPath/WinPath.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0</TargetFramework>
66
<PublishReadyToRun>true</PublishReadyToRun>
7-
<Version>0.3.0</Version>
7+
<Version>0.3.1</Version>
88
<Authors>ANF-Studios</Authors>
99
<Description>A simple tool to add variables to your Path!</Description>
1010

0 commit comments

Comments
 (0)