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
|
/// 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.
|
/// the file was found. So the subfolder will start in the same directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="appName"></param>
|
||||||
/// <param name="filename">Filename</param>
|
/// <param name="filename">Filename</param>
|
||||||
public static void ArchiveOneDriveFile(string filename)
|
public static void ArchiveOneDriveFile(string appName, string filename)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -42,17 +43,27 @@ namespace OneDriveArchiver
|
|||||||
// start with parent year folder...
|
// start with parent year folder...
|
||||||
var fullYearFolderPath = Path.Combine(basePath ?? throw new InvalidOperationException(), fileYear);
|
var fullYearFolderPath = Path.Combine(basePath ?? throw new InvalidOperationException(), fileYear);
|
||||||
var fullMonthFolderPath = Path.Combine(Path.Combine(basePath, fileYear), fileMonth);
|
var fullMonthFolderPath = Path.Combine(Path.Combine(basePath, fileYear), fileMonth);
|
||||||
|
|
||||||
|
// create the directories if not existing...
|
||||||
if (!Directory.Exists(fullYearFolderPath)) Directory.CreateDirectory(fullYearFolderPath);
|
if (!Directory.Exists(fullYearFolderPath)) Directory.CreateDirectory(fullYearFolderPath);
|
||||||
// then month...
|
|
||||||
if (!Directory.Exists(fullMonthFolderPath)) Directory.CreateDirectory(fullMonthFolderPath);
|
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...
|
// then move the file...
|
||||||
File.Move(filename, Path.Combine(fullMonthFolderPath, fileNameWithOutPath));
|
File.Move(filename, newFullFileName);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
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)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
const string appName = "OneDriverArchiver";
|
||||||
|
|
||||||
if (args.Length != 1)
|
if (args.Length != 1)
|
||||||
{
|
{
|
||||||
// handle improper arguments
|
// handle improper arguments
|
||||||
Console.WriteLine(
|
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
|
else
|
||||||
{
|
{
|
||||||
// check if the directory to process really exists
|
// check if the directory to process really exists
|
||||||
if (!Directory.Exists(args[0]))
|
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
|
else
|
||||||
{
|
{
|
||||||
// normal processing...
|
// normal processing...
|
||||||
Console.WriteLine("OneDriverArchiver: starting up...");
|
Console.WriteLine($"{appName}: starting up...");
|
||||||
|
|
||||||
var startUpTime = DateTime.Now;
|
var startUpTime = DateTime.Now;
|
||||||
|
|
||||||
var filesToProcess = Directory.GetFiles(args[0]);
|
var filesToProcess = Directory.GetFiles(args[0]);
|
||||||
|
if (filesToProcess.Length > 1)
|
||||||
|
{
|
||||||
foreach (var item in filesToProcess)
|
foreach (var item in filesToProcess)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Processing file {item}...");
|
Console.WriteLine($"{appName}: Processing file {item}...");
|
||||||
|
|
||||||
// skip ourselves...
|
// skip ourselves...
|
||||||
if (item.Contains("OneDriveArchiver"))
|
if (item.Contains("OneDriveArchiver"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Skipping processing of my own executable. Proceeding...");
|
Console.WriteLine(
|
||||||
|
$"{appName}: Skipping processing of my own executable. Proceeding...");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// archive the file
|
// archive the file
|
||||||
IoHelper.ArchiveOneDriveFile(item);
|
IoHelper.ArchiveOneDriveFile(appName, item);
|
||||||
|
|
||||||
Console.WriteLine($"Processing for file {item} completed successfully.");
|
Console.WriteLine($"{appName}: Processing for file {item} completed successfully.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// no files found...
|
||||||
|
Console.WriteLine($"{appName}: No files found to process.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var endProcessingTime = DateTime.Now;
|
var endProcessingTime = DateTime.Now;
|
||||||
var processingTime = endProcessingTime - startUpTime;
|
var processingTime = endProcessingTime - startUpTime;
|
||||||
|
|
||||||
Console.WriteLine(
|
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