Skip to content

Commit

Permalink
Update Hazel to net 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
garytate committed Jul 26, 2022
1 parent 4180034 commit 01b709e
Show file tree
Hide file tree
Showing 24 changed files with 656 additions and 725 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ bld/
[Ll]og/
[Ll]ogs/

.idea/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
27 changes: 0 additions & 27 deletions .vscode/launch.json

This file was deleted.

42 changes: 0 additions & 42 deletions .vscode/tasks.json

This file was deleted.

19 changes: 5 additions & 14 deletions hazel.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hazel", "hazel\hazel.csproj", "{B094D55F-EC79-49EF-A993-25722347129A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hazel", "Hazel\Hazel.csproj", "{F5563AA2-EB04-4250-A9FB-CC0B19D9413D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B094D55F-EC79-49EF-A993-25722347129A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B094D55F-EC79-49EF-A993-25722347129A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B094D55F-EC79-49EF-A993-25722347129A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B094D55F-EC79-49EF-A993-25722347129A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2C1EFADF-9FDD-4F51-8F35-739985C88052}
{F5563AA2-EB04-4250-A9FB-CC0B19D9413D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5563AA2-EB04-4250-A9FB-CC0B19D9413D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5563AA2-EB04-4250-A9FB-CC0B19D9413D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5563AA2-EB04-4250-A9FB-CC0B19D9413D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Binary file removed hazel/.DS_Store
Binary file not shown.
104 changes: 104 additions & 0 deletions hazel/Modules/Activity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Hazel.Modules;

public class Activity
{
public void DisplayActivity(string directory, List<string> characters, List<string> logs)
{
bool isOutputDecided = false;
bool isOutput = false;
Int32 charResults, charDaysActive;
bool isCharActive;
List<string> results = new List<string>();
string outputFile = string.Empty;

while (!isOutputDecided)
{
Console.Write("Output to text file? [Y/N]: ");
string keyInput = Console.ReadKey().Key.ToString();
Console.WriteLine();
if (keyInput == "Y")
{
isOutput = true;
isOutputDecided = true;
}
else if (keyInput == "N")
{
isOutput = false;
isOutputDecided = true;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\nIncorrect value.");
Console.ResetColor();
}
}

if (isOutput)
{
string outputDir = Path.Combine(directory, "output");

if (!Directory.Exists(outputDir))
{
Directory.CreateDirectory(outputDir);
}

Console.Write("\nOutput file name: ");
string outputFileName = Console.ReadLine();

if (outputFileName == string.Empty)
{
outputFileName = "output";
}

outputFile = outputDir + "\\" + outputFileName + ".txt";
FileStream fs = File.Create(outputFile);
fs.Close();
}

foreach (string character in characters)
{
charResults = 0;
charDaysActive = 0;
isCharActive = false;
foreach (string logFile in logs)
{
string line;
System.IO.StreamReader log = new System.IO.StreamReader(logFile);

while ((line = log.ReadLine()) != null)
{
if (line.Contains(character))
{
charResults += 1;
isCharActive = true;
}
}

if (isCharActive)
{
charDaysActive += 1;
isCharActive = false;
}
}

results.Add(String.Format("{0}: {1} | {2}", character, charResults, charDaysActive));
}

if (isOutput)
{
System.IO.File.WriteAllLines(outputFile, results);
}

foreach (string result in results)
{
Console.WriteLine(result);
}

}
}
40 changes: 40 additions & 0 deletions hazel/Modules/Character.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Hazel.Modules;

public class Character
{
public List<string> GetAllCharacters(string directory)
{
List<string> characters = new List<string>();
string currentLine = string.Empty;
string charDirectory = Path.Combine(directory, "characters");
string charTextFile = Path.Combine(charDirectory, "characters.txt");

// We need to create the directory first if it doesn't exist.
if (!Directory.Exists(charDirectory))
{
Directory.CreateDirectory(charDirectory);
}

// We'll do a separate check encase the .txt was deleted
if (!File.Exists(charTextFile))
{
var characterFile = File.Create(charTextFile);
characterFile.Close(); // Allows the user to edit the file
Console.WriteLine("Enter characters (one per line) into /characters/characters.txt then press any key.");
Console.ReadKey();
}

System.IO.StreamReader charFile = new System.IO.StreamReader(charTextFile);
while ((currentLine = charFile.ReadLine()) != null)
{
characters.Add(currentLine);
}

return characters;
}
}
53 changes: 53 additions & 0 deletions hazel/Modules/Container.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Hazel.Modules;

public class Container
{

public void ReturnAllContainers(List<string> logs)
{

List<string> uniqueContainers = new List<string>();
Int32 containerIDPattern;

// Search from newest -> oldest logs, for up to date container names.
logs.Reverse();

foreach (string logFile in logs)
{
string currentLine;
System.IO.StreamReader log = new System.IO.StreamReader(logFile);

while ((currentLine = log.ReadLine()) != null)
{
if (currentLine.Contains("opened the '") && !(currentLine.Contains("vault.")))
{
// Check to see if container is unique
containerIDPattern = currentLine.IndexOf("#");
string[] sectionedLog = currentLine.Split("' #");
string ContainerID = sectionedLog[1].Substring(0, 5);

if (uniqueContainers.Contains(ContainerID))
{
// check if name has been updated
}
else
{
string[] ContainerName = sectionedLog[0].Split("opened the '");
if (ContainerName[1].Length == 0 || ContainerName[1] == " ")
{
ContainerName[1] = "null";
}

Console.WriteLine("#{0} - {1}", ContainerID, ContainerName[1]);
uniqueContainers.Add(ContainerID);
}
}
}
}
}
}
39 changes: 39 additions & 0 deletions hazel/Modules/Display.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using Octokit;

namespace Hazel.Modules;

public class Display
{
public void DisplayMenu(string[] options, List<string> logs, List<string> chars)
{

Console.WriteLine("Files Loaded: {0} || Characters Loaded: {1}", logs.Count, chars.Count);
for (int i = 0; i < options.Length; i++)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[{0}] ", i + 1);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(options[i]);
}

Console.ResetColor();

}

public async void NotifyRelease(string appVersion)
{
// Github Release Check
var client = new GitHubClient(new ProductHeaderValue("hazel"));
var releases = await client.Repository.Release.GetAll("garytate", "hazel");
var latest = releases[0];

if (appVersion != latest.TagName)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("There is a new update at https://github.com/garytate/hazel/releases");
Console.ResetColor();
}
}
}
33 changes: 33 additions & 0 deletions hazel/Modules/FileManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Hazel.Modules;

public class FileManager
{
public List<string> GetAllLogs(string directory)
{
List<string> logFiles = new List<string>();
string logDirectory = Path.Combine(directory, "logs");

// Create log folder if not existant.
if (!Directory.Exists(logDirectory))
{
Directory.CreateDirectory(logDirectory);
Console.WriteLine("Copy your log files into the /logs folder then press any key.");
Console.ReadKey();
}

// Collect all log files into a List<string>
foreach (string file in Directory.EnumerateFiles((logDirectory), "*.txt"))
{
logFiles.Add(file);
}

// List<string> - file paths of all log files.
return logFiles;

}
}
Loading

0 comments on commit 01b709e

Please sign in to comment.