Repository navigation
Expand file tree
/
Copy pathFileHandler.cs
More file actions
62 lines (54 loc) · 2.23 KB
/
Copy pathFileHandler.cs
File metadata and controls
62 lines (54 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KoRegex
{
public class FileHandler
{
private readonly string _sourceDirectory;
private readonly string _targetDirectory;
private readonly RegexOptionsJson _regexOptions;
public FileHandler(string sourceDirectory, string targetDirectory, RegexOptionsJson regexOptions)
{
_sourceDirectory = sourceDirectory;
_targetDirectory = targetDirectory;
_regexOptions = regexOptions;
}
public void HandleFiles()
{
var csFiles = Directory.GetFiles(_sourceDirectory, $"*.{_regexOptions.FileType}", SearchOption.AllDirectories);
int totalFiles = csFiles.Length;
int fileIndex = 0;
Stopwatch stopwatch = Stopwatch.StartNew();
foreach (var file in csFiles)
{
ProcessSingleFile(file);
fileIndex++;
if(!Start.Silent) UpdateProgress(fileIndex, totalFiles);
}
stopwatch.Stop();
Console.WriteLine($"\nCompleted in {stopwatch.Elapsed.TotalSeconds:F3} seconds.");
}
private void UpdateProgress(int fileIndex, int totalFiles)
{
double percent = (double)fileIndex / totalFiles;
int progressBarWidth = Console.WindowWidth - 20;
int progress = (int)(percent * progressBarWidth);
string progressBar = new String('=', progress) + '>';
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write($"{fileIndex}/{totalFiles} [{progressBar.PadRight(progressBarWidth)}] {percent:P0}\r");
}
private void ProcessSingleFile(string filePath)
{
string fileContent = File.ReadAllText(filePath);
string modifiedContent = FileProcessor.ModifyFileContent(fileContent, _regexOptions);
string fileName = Path.GetFileName(filePath);
string newFileName = $"Debug{fileName}";
string newFilePath = Path.Combine(_targetDirectory, newFileName);
File.WriteAllText(newFilePath, modifiedContent);
}
}
}