Skip to content

Commit

Permalink
v3.1: Invalid repo directory issue fixed, Help message with app versi…
Browse files Browse the repository at this point in the history
…on, Minor changes
  • Loading branch information
MetaNaveen committed Sep 18, 2024
1 parent c1befc4 commit 6ad13ac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 141 deletions.
2 changes: 1 addition & 1 deletion BackupGitRepo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PublishSingleFile>true</PublishSingleFile>
<!--<PublishTrimmed>true</PublishTrimmed> --><!-- Optional, for reducing size -->
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <!-- Optional, for including native libraries -->
<Version>3.0</Version>
<Version>3.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 4 additions & 9 deletions Extensions/PathExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace BackupGitRepo;
namespace BackupGitRepo.Extensions;

public static class PathExtensions {
// Checks if directory path is valid.
public static bool IsValidDirectoryPath (this string path) {
if (string.IsNullOrWhiteSpace (path)) return false;

Expand Down Expand Up @@ -29,23 +30,17 @@ public static string NormalizePathSeparators (this string path) {
// Gets ParentDirName or DrivePath without :\
public static string GetParentOrDrivePath (this string path) {
var cleanPath = path.Trim (Path.DirectorySeparatorChar);
// Normalize the path and check if it's a valid drive letter
if (cleanPath.Length == 2 && cleanPath[1] == ':') {
return cleanPath[..^1]; // Return drive letter path without trailing backslash
}
// Check if the path exists
if (!Directory.Exists (cleanPath) && !File.Exists (cleanPath)) {
return "Path does not exist.";
}
// Get the directory info
DirectoryInfo dirInfo = new DirectoryInfo (cleanPath);
// If it's a file, get its directory
var dirInfo = new DirectoryInfo (cleanPath);
if (dirInfo.Exists == false) {
dirInfo = new FileInfo (cleanPath).Directory!;
}
// Get parent directory
DirectoryInfo parentDir = dirInfo.Parent!;
// Return drive letter path if no parent directory (root directory case)
var parentDir = dirInfo.Parent!;
if (parentDir == null) {
return dirInfo.FullName; // This will be the root directory or drive letter path
}
Expand Down
121 changes: 0 additions & 121 deletions Extensions/SelfUpdate.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace BackupGitRepo;
namespace BackupGitRepo.Extensions;

public static class StringExtensions {
// Gets common path between 2 given paths.
public static string GetCommonPath (this string path1, string path2) {
var commonPath = "";
if (string.IsNullOrWhiteSpace (path1) || string.IsNullOrWhiteSpace (path2))
Expand Down
20 changes: 11 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LibGit2Sharp;
using System.Reflection;
using BackupGitRepo.Extensions;
using LibGit2Sharp;
using System.Text;
using Utils;

namespace BackupGitRepo;

Expand All @@ -16,11 +17,13 @@ static void Main (string[] args) {
Console.WriteLine ($"Self update failed! with error '{ex.Message}'.\n Running with the current version...");
}

if (args.Length == 0) {
var appName = Assembly.GetExecutingAssembly ().GetName ().Name;
if (string.IsNullOrEmpty (appName)) appName = "BackupGitRepo";
appName += ".exe";
Console.WriteLine ($"{appName} [-su | -ii] <RepoDirectoryPath> [<BackupDirectoryPath>]");
var appInfo = AssemblyUtils.GetAssemblyVersion ();
if (string.IsNullOrEmpty (appInfo.Name)) appInfo.Name = "BackupGitRepo";
appInfo.Name += ".exe";
Console.WriteLine ($"App Version: {appInfo.Major}.{appInfo.Minor}");

if (args.Length == 0) {
Console.WriteLine ($"USAGE: {appInfo.Name} [-su | -ii] <RepoDirectoryPath> [<BackupDirectoryPath>]");
Environment.Exit (-1);
}

Expand Down Expand Up @@ -49,9 +52,8 @@ static void Main (string[] args) {
using var repo = new Repository (sRepositoryDir); // Gets repo from the path to .git

sBackupDir = Path.GetFullPath (GetBackupDirectoryOrDefault (args, 1, repoName, repo.Head.FriendlyName));
var ext = Path.GetExtension (sBackupDir);
// Validates backup dir
if (!sBackupDir.IsValidDirectoryPath () || !string.IsNullOrEmpty (ext)) {
if (!sBackupDir.IsValidDirectoryPath ()) {
Console.WriteLine ($"Not a valid directory. '{sBackupDir}'");
Environment.Exit (-1);
}
Expand Down

0 comments on commit 6ad13ac

Please sign in to comment.