Firelance 0.1.5.0
- Functional filters. - Functional absolute and relative path converters.
This commit is contained in:
@@ -194,6 +194,7 @@ namespace DevConsole
|
||||
private static void CmdHelperActions()
|
||||
{
|
||||
Console.WriteLine("A. Convert SpecialPath to AbsolutePath");
|
||||
Console.WriteLine("B. Path and filter testing");
|
||||
Console.WriteLine("X. <--- Go back\n");
|
||||
Console.Write(":");
|
||||
|
||||
@@ -205,6 +206,16 @@ namespace DevConsole
|
||||
case "A":
|
||||
Console.WriteLine(Helpers.Converters.GetSpecialToAbsolutePath(Console.ReadLine().ToUpper()));
|
||||
break;
|
||||
case "B":
|
||||
//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 relPath = Helpers.Converters.MakeRelativePath(new List<string>() { Helpers.Converters.GetSpecialToAbsolutePath("%DOCUMENTS%") }, fullPath).First();
|
||||
|
||||
Console.WriteLine($"Full: {fullPath}");
|
||||
Console.WriteLine($"Relative Path: {relPath}");
|
||||
|
||||
PrintListValues(Helpers.Filters.FilterDirectory(fullPath, @"*.*", ""));
|
||||
break;
|
||||
case "X":
|
||||
break;
|
||||
}
|
||||
@@ -324,5 +335,10 @@ namespace DevConsole
|
||||
Console.WriteLine($"{item.Name}: {item.GetValue(data)}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintListValues(List<string> data)
|
||||
{
|
||||
foreach (var item in data) { Console.WriteLine(item); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace FirelanceMgr
|
||||
@@ -28,6 +29,28 @@ namespace FirelanceMgr
|
||||
|
||||
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
|
||||
@@ -47,5 +70,68 @@ namespace FirelanceMgr
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Filters
|
||||
{
|
||||
/// <summary>
|
||||
/// To deprecate.
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> GetFileList(string fullPath)
|
||||
{
|
||||
var result = new List<string>();
|
||||
foreach (var file in Directory.GetFiles(fullPath))
|
||||
{
|
||||
result.Add(file);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<string> FilterDirectory (string fullPath, string inclusionStr, string exclusionStr)
|
||||
{
|
||||
var filteredList = new List<string>();
|
||||
var inclusionList = Builder(fullPath, inclusionStr);
|
||||
var exclusionList = Builder(fullPath, exclusionStr);
|
||||
|
||||
foreach (var item in inclusionList)
|
||||
{
|
||||
if (exclusionList.Contains(item) == false) { filteredList.Add(item); }
|
||||
}
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
private static List<string> Builder(string fullPath, string filterStr)
|
||||
{
|
||||
var filteredList = new List<string>();
|
||||
var inclusionsList = new List<string>();
|
||||
|
||||
if (filterStr != string.Empty)
|
||||
{
|
||||
char delimeter = '|';
|
||||
string currentInclusion = string.Empty;
|
||||
foreach (char c in filterStr)
|
||||
{
|
||||
currentInclusion += c;
|
||||
if (c == delimeter)
|
||||
{
|
||||
inclusionsList.Add(currentInclusion.Trim(delimeter));
|
||||
currentInclusion = string.Empty;
|
||||
}
|
||||
}
|
||||
inclusionsList.Add(currentInclusion); // Add final inclusion
|
||||
|
||||
foreach (var item in inclusionsList)
|
||||
foreach (var file in Directory.GetFiles(fullPath, item, SearchOption.AllDirectories))
|
||||
{
|
||||
filteredList.Add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user