Firelance 0.1.5.1

- Refactored filters
- Removed path helpers for minimal redundancy
- Crude but functional CopyDirectory function
This commit is contained in:
2020-07-08 19:46:52 +01:00
parent 89486560b4
commit a819e37fe7
3 changed files with 38 additions and 34 deletions
+6 -2
View File
@@ -4,6 +4,7 @@ using MongoDB.Bson;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO;
using System.Linq; using System.Linq;
namespace DevConsole namespace DevConsole
@@ -208,13 +209,16 @@ namespace DevConsole
break; break;
case "B": case "B":
//var dir = Helpers.Filters.GetFileList(@"D:\Temp"); //var dir = Helpers.Filters.GetFileList(@"D:\Temp");
string fullPath = Helpers.Converters.MakeAbsolutePath(new List<string>() { Helpers.Converters.GetSpecialToAbsolutePath("%DOCUMENTS%") }, @"BioWare\Mass Effect Andromeda").First(); string fullPath = Path.Combine(Helpers.Converters.GetSpecialToAbsolutePath("%DOCUMENTS%") , @"BioWare\Mass Effect Andromeda");
string relPath = Helpers.Converters.MakeRelativePath(new List<string>() { Helpers.Converters.GetSpecialToAbsolutePath("%DOCUMENTS%") }, fullPath).First(); string relPath = fullPath.Replace(Helpers.Converters.GetSpecialToAbsolutePath("%DOCUMENTS%") + "\\", string.Empty);
Console.WriteLine($"Full: {fullPath}"); Console.WriteLine($"Full: {fullPath}");
Console.WriteLine($"Relative Path: {relPath}"); Console.WriteLine($"Relative Path: {relPath}");
PrintListValues(Helpers.Filters.FilterDirectory(fullPath, @"*.*", "")); PrintListValues(Helpers.Filters.FilterDirectory(fullPath, @"*.*", ""));
FSManipulation.CopyDirectory(
fullPath,
fullPath.Replace(Helpers.Converters.GetSpecialToAbsolutePath("%DOCUMENTS%") + "\\", @"D:\Temp\TEST\"));
break; break;
case "X": case "X":
break; break;
+22
View File
@@ -0,0 +1,22 @@
using System.IO;
namespace FirelanceMgr
{
public static class FSManipulation
{
public static bool CopyDirectory(string source, string destination)
{
foreach (var item in Directory.GetDirectories(source, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(item.Replace(source, destination));
}
foreach (var item in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
{
File.Copy(item, item.Replace(source, destination), true);
}
return Directory.Exists(destination);
}
}
}
+10 -32
View File
@@ -29,28 +29,6 @@ namespace FirelanceMgr
return d.Where(x => x.Key.Contains(specialPath)).Select(x => x.Value).Single(); return d.Where(x => x.Key.Contains(specialPath)).Select(x => x.Value).Single();
} }
public static List<string> MakeRelativePath(List<string> directory, string fullPath)
{
var result = new List<string>();
foreach (var item in directory)
{
if (fullPath.StartsWith(item.ToString())) { result.Add(fullPath.TrimStart(item.ToCharArray())); }
}
return result;
}
public static List<string> MakeAbsolutePath(List<string> directory, string relPath)
{
var result = new List<string>();
foreach (var item in directory)
{
result.Add(Path.Combine(item, relPath));
}
return result;
}
} }
public static class Parsers public static class Parsers
@@ -89,7 +67,7 @@ namespace FirelanceMgr
return result; return result;
} }
public static List<string> FilterDirectory (string fullPath, string inclusionStr, string exclusionStr) public static List<string> FilterDirectory(string fullPath, string inclusionStr, string exclusionStr)
{ {
var filteredList = new List<string>(); var filteredList = new List<string>();
var inclusionList = Builder(fullPath, inclusionStr); var inclusionList = Builder(fullPath, inclusionStr);
@@ -106,24 +84,24 @@ namespace FirelanceMgr
private static List<string> Builder(string fullPath, string filterStr) private static List<string> Builder(string fullPath, string filterStr)
{ {
var filteredList = new List<string>(); var filteredList = new List<string>();
var inclusionsList = new List<string>(); var filters = new List<string>();
if (filterStr != string.Empty) if (filterStr != string.Empty)
{ {
char delimeter = '|'; char delimeter = '|';
string currentInclusion = string.Empty; string currentFilter = string.Empty;
foreach (char c in filterStr) foreach (char f in filterStr)
{ {
currentInclusion += c; currentFilter += f;
if (c == delimeter) if (f == delimeter)
{ {
inclusionsList.Add(currentInclusion.Trim(delimeter)); filters.Add(currentFilter.Trim(delimeter));
currentInclusion = string.Empty; currentFilter = string.Empty;
} }
} }
inclusionsList.Add(currentInclusion); // Add final inclusion filters.Add(currentFilter); // Add final inclusion
foreach (var item in inclusionsList) foreach (var item in filters)
foreach (var file in Directory.GetFiles(fullPath, item, SearchOption.AllDirectories)) foreach (var file in Directory.GetFiles(fullPath, item, SearchOption.AllDirectories))
{ {
filteredList.Add(file); filteredList.Add(file);