Did cleanup of code base for .NET core version.
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,49 +11,60 @@ namespace OneDriveArchiver
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
const string appName = "OneDriverArchiver";
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
// handle improper arguments
|
||||
Console.WriteLine(
|
||||
"OneDriverArchiver: Please specify a directory with files mapped to a Microsoft OneDrive folder.");
|
||||
$"{appName}: Please specify a directory with files mapped to a Microsoft OneDrive folder.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if the directory to process really exists
|
||||
if (!Directory.Exists(args[0]))
|
||||
{
|
||||
Console.WriteLine($"The directory '{args[0]}' does not exist. Please specify another one.");
|
||||
Console.WriteLine($"{appName}: The directory '{args[0]}' does not exist. Please specify another one.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal processing...
|
||||
Console.WriteLine("OneDriverArchiver: starting up...");
|
||||
Console.WriteLine($"{appName}: starting up...");
|
||||
|
||||
var startUpTime = DateTime.Now;
|
||||
|
||||
var filesToProcess = Directory.GetFiles(args[0]);
|
||||
foreach (var item in filesToProcess)
|
||||
if (filesToProcess.Length > 1)
|
||||
{
|
||||
Console.WriteLine($"Processing file {item}...");
|
||||
|
||||
// skip ourselves...
|
||||
if (item.Contains("OneDriveArchiver"))
|
||||
foreach (var item in filesToProcess)
|
||||
{
|
||||
Console.WriteLine("Skipping processing of my own executable. Proceeding...");
|
||||
continue;
|
||||
Console.WriteLine($"{appName}: Processing file {item}...");
|
||||
|
||||
// skip ourselves...
|
||||
if (item.Contains("OneDriveArchiver"))
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"{appName}: Skipping processing of my own executable. Proceeding...");
|
||||
continue;
|
||||
}
|
||||
|
||||
// archive the file
|
||||
IoHelper.ArchiveOneDriveFile(appName, item);
|
||||
|
||||
Console.WriteLine($"{appName}: Processing for file {item} completed successfully.");
|
||||
}
|
||||
|
||||
// archive the file
|
||||
IoHelper.ArchiveOneDriveFile(item);
|
||||
|
||||
Console.WriteLine($"Processing for file {item} completed successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// no files found...
|
||||
Console.WriteLine($"{appName}: No files found to process.");
|
||||
}
|
||||
|
||||
var endProcessingTime = DateTime.Now;
|
||||
var processingTime = endProcessingTime - startUpTime;
|
||||
|
||||
Console.WriteLine(
|
||||
$"OneDriverArchiver: Processing completed.\nProcessing time = {processingTime}\nNumber of files = {filesToProcess.Length}.");
|
||||
$"{appName}: Processing completed.\n{appName}: Processing time = {processingTime}\n{appName}: Number of files = {filesToProcess.Length}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user