Did cleanup of code base for .NET core version.

This commit is contained in:
2019-12-28 19:53:02 +01:00
parent 36d201d6ef
commit ddcc262199
4 changed files with 23 additions and 23 deletions

2
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,2 @@
# Default ignored files
/.idea.OneDriveArchiver/.idea/workspace.xml

View File

@@ -1,6 +1,8 @@
#region Using Statements #region Using Statements
using System; using System;
using System.IO; using System.IO;
#endregion #endregion
namespace OneDriveArchiver namespace OneDriveArchiver
@@ -8,21 +10,18 @@ namespace OneDriveArchiver
public static class IoHelper public static class IoHelper
{ {
/// <summary> /// <summary>
/// Archives a one drive file. It takes the file creation date and month, /// Archives a one drive file. It takes the file creation date and month,
/// creates the necessary folder structure (if necessary) i.e. Year\Month and /// creates the necessary folder structure (if necessary) i.e. Year\Month and
/// moves the file to the (new) target folder. The Sync engine of OneDrive then /// moves the file to the (new) target folder. The Sync engine of OneDrive then
/// 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="filename">Filename</param> /// <param name="filename">Filename</param>
public static void ArchiveOneDriveFile(string filename) public static void ArchiveOneDriveFile(string filename)
{ {
try try
{ {
if (string.IsNullOrEmpty(filename)) if (string.IsNullOrEmpty(filename)) throw new ArgumentException("filename cannot be null.");
{
throw new ArgumentException("filename cannot be null.");
}
// do a check if the file is empty... // do a check if the file is empty...
var fi = new FileInfo(filename); var fi = new FileInfo(filename);
@@ -32,25 +31,20 @@ namespace OneDriveArchiver
File.Delete(filename); File.Delete(filename);
return; return;
} }
var dateModified = File.GetLastWriteTime(filename); var dateModified = File.GetLastWriteTime(filename);
var fileMonth = dateModified.Month.ToString("D2"); var fileMonth = dateModified.Month.ToString("D2");
var fileYear = dateModified.Year.ToString(); var fileYear = dateModified.Year.ToString();
var basePath = Path.GetDirectoryName(filename); var basePath = Path.GetDirectoryName(filename);
var fileNameWithOutPath = Path.GetFileName(filename); var fileNameWithOutPath = Path.GetFileName(filename);
// check if we have to create either year or month folder... // check if we have to create either year or month folder...
// 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);
if (!Directory.Exists(fullYearFolderPath)) if (!Directory.Exists(fullYearFolderPath)) Directory.CreateDirectory(fullYearFolderPath);
{
Directory.CreateDirectory(fullYearFolderPath);
}
// then month... // then month...
if (!Directory.Exists(fullMonthFolderPath)) if (!Directory.Exists(fullMonthFolderPath)) Directory.CreateDirectory(fullMonthFolderPath);
{
Directory.CreateDirectory(fullMonthFolderPath);
}
// then move the file... // then move the file...
File.Move(filename, Path.Combine(fullMonthFolderPath, fileNameWithOutPath)); File.Move(filename, Path.Combine(fullMonthFolderPath, fileNameWithOutPath));

View File

@@ -1,18 +1,21 @@
#region Using Statements #region Using Statements
using System; using System;
using System.IO; using System.IO;
#endregion #endregion
namespace OneDriveArchiver namespace OneDriveArchiver
{ {
class Program internal class Program
{ {
static void Main(string[] args) private static void Main(string[] args)
{ {
if (args.Length != 1) if (args.Length != 1)
{ {
// handle improper arguments // handle improper arguments
Console.WriteLine("OneDriverArchiver: Please specify a directory with files mapped to a Microsoft OneDrive folder."); Console.WriteLine(
"OneDriverArchiver: Please specify a directory with files mapped to a Microsoft OneDrive folder.");
} }
else else
{ {
@@ -49,7 +52,8 @@ namespace OneDriveArchiver
var endProcessingTime = DateTime.Now; var endProcessingTime = DateTime.Now;
var processingTime = endProcessingTime - startUpTime; var processingTime = endProcessingTime - startUpTime;
Console.WriteLine($"OneDriverArchiver: Processing completed.\nProcessing time = {processingTime}\nNumber of files = {filesToProcess.Length}."); Console.WriteLine(
$"OneDriverArchiver: Processing completed.\nProcessing time = {processingTime}\nNumber of files = {filesToProcess.Length}.");
} }
} }
} }

View File

@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]