Add project files.

This commit is contained in:
Administrator
2017-01-02 11:46:00 +01:00
parent 8d43a740a0
commit 89a6addc1b
6 changed files with 231 additions and 0 deletions

22
OneDriveArchiver.sln Normal file
View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneDriveArchiver", "OneDriveArchiver\OneDriveArchiver.csproj", "{92B729E9-710C-4FF6-90F6-C9100AD974C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{92B729E9-710C-4FF6-90F6-C9100AD974C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92B729E9-710C-4FF6-90F6-C9100AD974C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92B729E9-710C-4FF6-90F6-C9100AD974C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92B729E9-710C-4FF6-90F6-C9100AD974C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@@ -0,0 +1,66 @@
#region Using Statements
using System;
using System.IO;
#endregion
namespace OneDriveArchiver
{
public static class IoHelper
{
/// <summary>
/// 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
/// 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
/// the file was found. So the subfolder will start in the same directory.
/// </summary>
/// <param name="filename">Filename</param>
public static void ArchiveOneDriveFile(string filename)
{
try
{
if (string.IsNullOrEmpty(filename))
{
throw new ArgumentException("filename cannot be null.");
}
// do a check if the file is empty...
FileInfo fi = new FileInfo(filename);
if (fi.Length == 0)
{
Console.WriteLine($"Deleting file {filename} as it has zero bytes content.");
File.Delete(filename);
return;
}
var dateModified = File.GetLastWriteTime(filename);
var fileMonth = dateModified.Month.ToString("D2");
var fileYear = dateModified.Year.ToString();
var basePath = Path.GetDirectoryName(filename);
var fileNameWithOutPath = Path.GetFileName(filename);
// check if we have to create either year or month folder...
// start with parent year folder...
var fullYearFolderPath = Path.Combine(basePath, fileYear);
var fullMonthFolderPath = Path.Combine(Path.Combine(basePath, fileYear), fileMonth);
if (!Directory.Exists(fullYearFolderPath))
{
Directory.CreateDirectory(fullYearFolderPath);
}
// then month...
if (!Directory.Exists(fullMonthFolderPath))
{
Directory.CreateDirectory(fullMonthFolderPath);
}
// then move the file...
File.Move(filename, Path.Combine(fullMonthFolderPath, fileNameWithOutPath));
}
catch (Exception ex)
{
Console.WriteLine(
$"Exception while backing up onedrive file. Message = {ex.Message}, Stacktrace = {ex.StackTrace}");
}
}
}
}

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{92B729E9-710C-4FF6-90F6-C9100AD974C8}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OneDriveArchiver</RootNamespace>
<AssemblyName>OneDriveArchiver</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IoHelper.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,40 @@
using System;
using System.IO;
namespace OneDriveArchiver
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
// handle improper arguments
Console.WriteLine("OneDriverArchiver: Please specify a directory with images mapped to a onedrive folder.");
}
else
{
// normal processing...
Console.WriteLine("OneDriverArchiver: starting up...");
var startUpTime = DateTime.Now;
var filesToProcess = Directory.GetFiles(args[0]);
foreach (var item in filesToProcess)
{
Console.WriteLine($"Processing file {item}...");
// archive the file
IoHelper.ArchiveOneDriveFile(item);
Console.Write($"Processing for file {item} completed successfully.");
}
var endProcessingTime = DateTime.Now;
var processingTime = endProcessingTime - startUpTime;
Console.WriteLine($"OneDriverArchiver: Processing completed.\nProcessing time = {processingTime}");
}
}
}
}

View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OneDriveArchiver")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OneDriveArchiver")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("92b729e9-710c-4ff6-90f6-c9100ad974c8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]