Archived
Implemented most of the features required however i have not tested them yet.
Signed-off-by: Wickeddev123 <wickedempire111@outlook.com>
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibCopy", "LibCopy\LibCopy.csproj", "{D083DB64-1913-4FAC-9894-1A66E4EFF86D}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{D083DB64-1913-4FAC-9894-1A66E4EFF86D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D083DB64-1913-4FAC-9894-1A66E4EFF86D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D083DB64-1913-4FAC-9894-1A66E4EFF86D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D083DB64-1913-4FAC-9894-1A66E4EFF86D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommandLineParser" Version="2.7.82" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using CommandLine;
|
||||||
|
|
||||||
|
//Todo: If Verbose is set, output the total size of the files.
|
||||||
|
|
||||||
|
// Exit Codes:
|
||||||
|
// 0: Success
|
||||||
|
// 1: Bad Directory
|
||||||
|
// 2: Bad files (if all the files are bad for example a bad path)
|
||||||
|
|
||||||
|
namespace LibCopy
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Information required from the command line parser.
|
||||||
|
/// </summary>
|
||||||
|
public class Options
|
||||||
|
{
|
||||||
|
[Option('v', "Verbose", Required = false, HelpText = "Outputs current state of the application.", Default = false)]
|
||||||
|
public bool Verbose { get; set; }
|
||||||
|
[Option('f', "File Paths", Required = true, HelpText = "Gives the application the file paths for the files to copy.")]
|
||||||
|
public string[] FilesToCopy { get; set; }
|
||||||
|
[Option('d', "Directory to copy files into.", Required = true, HelpText = "Gives the application the place where the files will be copied into.")]
|
||||||
|
public string Directory { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Parser.Default.ParseArguments<Options>(args).WithParsed(o => {
|
||||||
|
Utils.Copy(o.FilesToCopy, o.Directory, o.Verbose);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibCopy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Random Util functions.
|
||||||
|
/// </summary>
|
||||||
|
public static class Utils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies a file exists based on the path given though the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="location">the path to the file.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool VerifyFile(string location) => File.Exists(location);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies a directory based on the path given though the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directory">the path to the directory.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool VerifyDirectory(string directory) => Directory.Exists(directory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the file's name from the filepath.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string FileName(string filePath)
|
||||||
|
{
|
||||||
|
// Todo: Find a less hacky method of getting the file's name.
|
||||||
|
string[] name = filePath.Split(new char[] {'\\', '/'});
|
||||||
|
return name[name.Length];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copies the files into the specified directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="files">File Paths.</param>
|
||||||
|
/// <param name="directory">Directory Path</param>
|
||||||
|
/// <param name="verbose">specifies if console output is requires.</param>
|
||||||
|
public static void Copy(string[] files, string directory, bool verbose)
|
||||||
|
{
|
||||||
|
if (VerifyDirectory(directory))
|
||||||
|
Environment.Exit(1);
|
||||||
|
|
||||||
|
int badFiles = 0;
|
||||||
|
|
||||||
|
Parallel.ForEach(files, (x) =>
|
||||||
|
{
|
||||||
|
if (!VerifyFile(x))
|
||||||
|
{
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
//Todo: Better Logging.
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.Write($"File {x} has errored for some reason; " +
|
||||||
|
$"most likely because the filepath is incorrect.");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
Interlocked.Increment(ref badFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
File.Copy(x, $"{directory}\\{FileName(x)}");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (files.Length == badFiles)
|
||||||
|
Environment.Exit(2);
|
||||||
|
else
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user