Skip to content

Commit 0fc33fa

Browse files
Merge pull request #1 from TheGuitarleader/develop
Pulling original code
2 parents cad11d1 + 97ba822 commit 0fc33fa

82 files changed

Lines changed: 5152 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dotnet.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v4
20+
with:
21+
dotnet-version: 9.0.x
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
- name: Build
25+
run: dotnet build --no-restore
26+
- name: Test
27+
run: dotnet test --no-build --verbosity normal

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.user
1010
*.userosscache
1111
*.sln.docstates
12+
*.sln
1213

1314
# User-specific files (MonoDevelop/Xamarin Studio)
1415
*.userprefs
@@ -34,6 +35,7 @@ bld/
3435

3536
# Visual Studio 2015/2017 cache/options directory
3637
.vs/
38+
3739
# Uncomment if you have tasks that create the project's static files in wwwroot
3840
#wwwroot/
3941

@@ -82,8 +84,6 @@ StyleCopReport.xml
8284
*.pgc
8385
*.pgd
8486
*.rsp
85-
# but not Directory.Build.rsp, as it configures directory-level build defaults
86-
!Directory.Build.rsp
8787
*.sbr
8888
*.tlb
8989
*.tli
@@ -95,7 +95,7 @@ StyleCopReport.xml
9595
*.tlog
9696
*.vspscc
9797
*.vssscc
98-
.builds
98+
.build
9999
*.pidb
100100
*.svclog
101101
*.scc
@@ -257,7 +257,6 @@ Generated_Code/
257257
# to a newer Visual Studio version. Backup files are not needed,
258258
# because we have git ;-)
259259
_UpgradeReport_Files/
260-
Backup*/
261260
UpgradeLog*.XML
262261
UpgradeLog*.htm
263262
ServiceFabricBackup/
@@ -398,3 +397,4 @@ FodyWeavers.xsd
398397

399398
# JetBrains Rider
400399
*.sln.iml
400+
.idea/

LICENSE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Parallel © 2025 by [Entex Interactive, LLC](https://www.entexinteractive.com/) is licensed under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)
1+
Parallel © 2025 by [Kyle Ebbinga](https://github.com/TheGuitarleader/Parallel) is licensed under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)
2+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2025 Kyle Ebbinga
2+
3+
using System.CommandLine;
4+
using Parallel.Cli.Utils;
5+
using Parallel.Core.Database;
6+
using Parallel.Core.IO.FileSystem;
7+
using Parallel.Core.Settings;
8+
using Parallel.Core.Utils;
9+
10+
namespace Parallel.Cli.Commands
11+
{
12+
public class ConfigCommand : Command
13+
{
14+
private Command addCmd = new("add", "Adds a new profile configuration.");
15+
private Command editCmd = new("edit", "Edits a profile configuration.");
16+
private Command viewCmd = new("view", "Shows the profile configuration.");
17+
private Command setCmd = new("set", "Sets a new profile configuration.");
18+
private Command delCmd = new("delete", "Deletes a profile configuration.");
19+
20+
public ConfigCommand() : base("config", "View or edit the profile configurations.")
21+
{
22+
this.SetHandler(() =>
23+
{
24+
//ProfileConfig profile = ProfileConfig.Load();
25+
CommandLine.WriteLine($"Current profile: '{Program.Settings.Profiles.FirstOrDefault()}'");
26+
});
27+
28+
this.AddCommand(addCmd);
29+
addCmd.SetHandler(() =>
30+
{
31+
CommandLine.WriteLine("Creating new database credentials...", ConsoleColor.DarkGray);
32+
DatabaseCredentials dbc = new DatabaseCredentials();
33+
dbc.Provider = Enum.Parse<DatabaseProvider>(CommandLine.ReadString($"Provider ({string.Join(", ", Enum.GetNames(typeof(DatabaseProvider)))})"), true);
34+
if (dbc.Provider == DatabaseProvider.Local)
35+
{
36+
dbc = DatabaseCredentials.Local;
37+
}
38+
else
39+
{
40+
dbc.Address = CommandLine.ReadString("Address");
41+
dbc.Username = CommandLine.ReadString("Username");
42+
dbc.Password = CommandLine.ReadPassword("Password");
43+
dbc.Name = CommandLine.ReadString("Name");
44+
}
45+
46+
CommandLine.WriteLine("Creating new file system credentials...", ConsoleColor.DarkGray);
47+
FileSystemCredentials fsc = new FileSystemCredentials();
48+
fsc.Service = Enum.Parse<FileService>(CommandLine.ReadString($"Service ({string.Join(", ", Enum.GetNames(typeof(FileService)))})"), true);
49+
if (fsc.Service == FileService.Local)
50+
{
51+
fsc.RootDirectory = CommandLine.ReadString("Root");
52+
}
53+
else if (fsc.Service == FileService.Cloud)
54+
{
55+
fsc.Address = CommandLine.ReadString("Bucket Name");
56+
fsc.Username = CommandLine.ReadString("Access Key");
57+
fsc.Password = CommandLine.ReadPassword("Secret Key");
58+
}
59+
else
60+
{
61+
fsc.RootDirectory = CommandLine.ReadString("Root");
62+
fsc.Address = CommandLine.ReadString("Address");
63+
fsc.Username = CommandLine.ReadString("Username");
64+
fsc.Password = CommandLine.ReadPassword("Password");
65+
}
66+
67+
fsc.Encrypt = CommandLine.ReadBool("Encrypt files? (y/n)", false);
68+
fsc.EncryptionKey = HashGenerator.GenerateHash(32, true);
69+
70+
string profileName = CommandLine.ReadString("Profile Name");
71+
ProfileConfig profile = new ProfileConfig(profileName, dbc, fsc);
72+
profile.SaveToFile();
73+
74+
CommandLine.WriteLine($"Saved new connection profile: '{profile.Name}'");
75+
});
76+
77+
this.AddCommand(setCmd);
78+
setCmd.SetHandler(() =>
79+
{
80+
81+
});
82+
}
83+
}
84+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2025 Kyle Ebbinga
2+
3+
using System.CommandLine;
4+
5+
namespace Parallel.Cli.Commands
6+
{
7+
public class DecryptCommand : Command
8+
{
9+
public DecryptCommand() : base("decrypt", "Decrypts a file or directory.")
10+
{
11+
12+
}
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2025 Kyle Ebbinga
2+
3+
using System.CommandLine;
4+
5+
namespace Parallel.Cli.Commands
6+
{
7+
public class EncryptCommand : Command
8+
{
9+
private readonly Argument<string> sourceArg = new("path", "The source path to encrypt.");
10+
11+
public EncryptCommand() : base("encrypt", "Encrypts a file or directory.")
12+
{
13+
14+
}
15+
}
16+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2025 Kyle Ebbinga
2+
3+
using System.CommandLine;
4+
using System.Diagnostics;
5+
using System.IO.Compression;
6+
using Parallel.Cli.Utils;
7+
8+
namespace Parallel.Cli.Commands
9+
{
10+
public class UnzipCommand : Command
11+
{
12+
private readonly Argument<string> sourceArg = new("path", "The source path of files to unzip.");
13+
private readonly Option<bool> keepOpt = new(["--keep", "-k"], "If the original files should be kept.");
14+
15+
private Stopwatch _sw;
16+
private readonly List<Task> _tasks = new List<Task>();
17+
private int _totalTasks = 0;
18+
19+
public UnzipCommand() : base("unzip", "Unzips files in a directory.")
20+
{
21+
this.AddArgument(sourceArg);
22+
this.AddOption(keepOpt);
23+
this.SetHandler(async (path, keep) =>
24+
{
25+
_sw = Stopwatch.StartNew();
26+
CommandLine.WriteLine($"Scanning for files in {path}...", ConsoleColor.DarkGray);
27+
string[] files = Directory.GetFiles(path, $"*.gz", SearchOption.AllDirectories);
28+
if (files.Length == 0)
29+
{
30+
CommandLine.WriteLine("No files found to unzip!", ConsoleColor.Yellow);
31+
return;
32+
}
33+
34+
CommandLine.WriteLine($"Unzipping {files.Length.ToString("N0")} files...", ConsoleColor.DarkGray);
35+
_totalTasks = files.Length;
36+
foreach (string file in files)
37+
{
38+
StartDecompressFile(file, keep);
39+
}
40+
41+
await Task.WhenAll(_tasks);
42+
CommandLine.WriteLine($"Successfully unzipped {files.Length.ToString("N0")} files in {_sw.Elapsed}.", ConsoleColor.Green);
43+
}, sourceArg, keepOpt);
44+
}
45+
46+
private void StartDecompressFile(string path, bool keep)
47+
{
48+
Task decompTask = Task.Run(() =>
49+
{
50+
DecompressFile(path, keep);
51+
});
52+
53+
decompTask.ContinueWith(t => t.Dispose());
54+
_tasks.Add(decompTask);
55+
}
56+
57+
private void DecompressFile(string path, bool keep)
58+
{
59+
if (File.Exists(path))
60+
{
61+
using (FileStream openFile = File.OpenRead(path))
62+
using (FileStream createFile = new FileStream(path.Replace(".gz", string.Empty), FileMode.OpenOrCreate))
63+
using (GZipStream gZip = new GZipStream(openFile, CompressionMode.Decompress))
64+
{
65+
gZip.CopyTo(createFile);
66+
}
67+
68+
if (!keep)
69+
{
70+
File.SetAttributes(path, ~FileAttributes.ReadOnly & File.GetAttributes(path));
71+
File.Delete(path);
72+
}
73+
}
74+
75+
CommandLine.ProgressBar(_tasks.Count(t => t.IsCompleted), _totalTasks, _sw.Elapsed, ConsoleColor.DarkGray);
76+
}
77+
}
78+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2025 Kyle Ebbinga
2+
3+
using System.CommandLine;
4+
using System.Diagnostics;
5+
using System.IO.Compression;
6+
using System.Runtime.CompilerServices;
7+
using Parallel.Cli.Utils;
8+
using SQLitePCL;
9+
10+
namespace Parallel.Cli.Commands
11+
{
12+
public class ZipCommand : Command
13+
{
14+
private readonly Argument<string> sourceArg = new("path", "The source path of files to zip.");
15+
private readonly Option<bool> keepOpt = new(["--keep", "-k"], "If the original files should be kept.");
16+
17+
private Stopwatch _sw = new Stopwatch();
18+
private readonly List<Task> _tasks = new List<Task>();
19+
private int _totalTasks = 0;
20+
21+
public ZipCommand() : base("zip", "Zips files in a directory.")
22+
{
23+
this.AddArgument(sourceArg);
24+
this.AddOption(keepOpt);
25+
this.SetHandler(async (path, keep) =>
26+
{
27+
_sw = Stopwatch.StartNew();
28+
CommandLine.WriteLine($"Scanning for files in {path}...", ConsoleColor.DarkGray);
29+
string[] files = Directory.EnumerateFiles(path, $"*", SearchOption.AllDirectories).Where(f => !f.EndsWith(".gz")).ToArray();
30+
if (files.Length == 0)
31+
{
32+
CommandLine.WriteLine("No files found to zip!", ConsoleColor.Yellow);
33+
return;
34+
}
35+
36+
CommandLine.WriteLine($"Zipping {files.Length.ToString("N0")} files...", ConsoleColor.DarkGray);
37+
_totalTasks = files.Length;
38+
foreach (string file in files)
39+
{
40+
StartCompressFile(file, keep);
41+
}
42+
43+
await Task.WhenAll(_tasks);
44+
CommandLine.WriteLine($"Successfully zipped {files.Length.ToString("N0")} files in {_sw.Elapsed}.", ConsoleColor.Green);
45+
}, sourceArg, keepOpt);
46+
}
47+
48+
private void StartCompressFile(string path, bool keep)
49+
{
50+
Task compTask = Task.Run(() =>
51+
{
52+
CompressFile(path, keep);
53+
});
54+
55+
compTask.ContinueWith(t => t.Dispose());
56+
_tasks.Add(compTask);
57+
}
58+
59+
private void CompressFile(string path, bool keep)
60+
{
61+
if (File.Exists(path))
62+
{
63+
using (FileStream openFile = File.OpenRead(path))
64+
using (FileStream createFile = new FileStream($"{path}.gz", FileMode.OpenOrCreate))
65+
using (GZipStream gZip = new GZipStream(createFile, CompressionLevel.SmallestSize))
66+
{
67+
openFile.CopyTo(gZip);
68+
}
69+
70+
if (!keep)
71+
{
72+
File.SetAttributes(path, ~FileAttributes.ReadOnly & File.GetAttributes(path));
73+
File.Delete(path);
74+
}
75+
}
76+
77+
CommandLine.ProgressBar(_tasks.Count(t => t.IsCompleted), _totalTasks, _sw.Elapsed, ConsoleColor.DarkGray);
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)