Did cleanup of code base for .NET core version.

This commit is contained in:
2020-01-17 17:45:25 +01:00
parent 453dcc8680
commit f549bf036a
2 changed files with 43 additions and 21 deletions

View File

@@ -16,8 +16,9 @@ namespace OneDriveArchiver
/// will sync the changes being made back to the cloud. Base Path is the path where
/// the file was found. So the subfolder will start in the same directory.
/// </summary>
/// <param name="appName"></param>
/// <param name="filename">Filename</param>
public static void ArchiveOneDriveFile(string filename)
public static void ArchiveOneDriveFile(string appName, string filename)
{
try
{
@@ -42,17 +43,27 @@ namespace OneDriveArchiver
// start with parent year folder...
var fullYearFolderPath = Path.Combine(basePath ?? throw new InvalidOperationException(), fileYear);
var fullMonthFolderPath = Path.Combine(Path.Combine(basePath, fileYear), fileMonth);
// create the directories if not existing...
if (!Directory.Exists(fullYearFolderPath)) Directory.CreateDirectory(fullYearFolderPath);
// then month...
if (!Directory.Exists(fullMonthFolderPath)) Directory.CreateDirectory(fullMonthFolderPath);
var newFullFileName = Path.Combine(fullMonthFolderPath, fileNameWithOutPath);
// check if the file at the designated new archive location exists. If so, remove the existing file
// and replace it with the new copy.
if (File.Exists(newFullFileName))
{
Console.WriteLine($"{appName}: archive file exists at designated folder. Removing the old file for copying the new one instead.");
File.Delete(newFullFileName);
}
// then move the file...
File.Move(filename, Path.Combine(fullMonthFolderPath, fileNameWithOutPath));
File.Move(filename, newFullFileName);
}
catch (Exception ex)
{
Console.WriteLine(
$"Exception while backing up onedrive file. Message = {ex.Message}, Stacktrace = {ex.StackTrace}");
$"Exception while backing up OneDrive file. Message = {ex.Message}, Stacktrace = {ex.StackTrace}");
}
}
}