-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
97 lines (80 loc) · 2.94 KB
/
Program.cs
File metadata and controls
97 lines (80 loc) · 2.94 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Author: Nikolay Dvurechensky
* Site: https://dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 03 апреля 2026 11:33:43
* Version: 1.0.7
*/
using System.Diagnostics;
using System.Text.Json;
using LizeriumFindChanges.Components;
using LizeriumFindChanges.Services;
const string configFileName = "config.json";
var config = await LoadOrCreateConfigAsync(configFileName);
if (config == null)
{
Console.WriteLine("[ERROR] Invalid config parameters. Please check the config.json file.");
return;
}
Console.WriteLine($"[x] Put [BEFORE]: {config.Before}");
Console.WriteLine($"[x] Put [AFTER]: {config.After}");
Console.WriteLine($"[x] Put [VERSION]: {config.Version}");
Console.WriteLine($"[x] Put [IS_MISSING_MODE]: {config.IsMissingFilesMode}");
Console.WriteLine($"[*]>Started...");
Stopwatch stopwatch = Stopwatch.StartNew();
var comparer = new CompareService();
if(config.IsMissingFilesMode)
{
var compareMissingFilesFolder = "MISSING";
if (!Directory.Exists(compareMissingFilesFolder))
Directory.CreateDirectory(compareMissingFilesFolder);
await comparer.ExtractMissingFilesFromBeforeAsync(
beforeDir: config.Before,
afterDir: config.After,
outputDir: compareMissingFilesFolder);
}
else
{
var data = await comparer.CompareAndLogChangesExtended(config.Before, config.After);
File.WriteAllText("manifest.json", data.ToString());
await comparer.CreateUpdateFolderAsync(data, config.After, config.Version);
}
stopwatch.Stop();
Console.WriteLine($"[*]>Success! [{stopwatch.ElapsedMilliseconds / 1000} s]");
// --- Методы ---
async Task<Config?> LoadOrCreateConfigAsync(string path)
{
if (!File.Exists(path))
{
// Создаем шаблонный файл с пустыми значениями
var template = new Config
{
Before = "",
After = "",
Version = ""
};
var json = JsonSerializer.Serialize(template, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(path, json);
Console.WriteLine($"[INFO] Config file created at '{path}'. Please fill in the required fields.");
return null; // не продолжаем дальше, ждем чтобы пользователь заполнил
}
try
{
var json = await File.ReadAllTextAsync(path);
var config = JsonSerializer.Deserialize<Config>(json);
// Проверяем на валидность - пусть параметры не пустые
if (config == null
|| string.IsNullOrWhiteSpace(config.Before)
|| string.IsNullOrWhiteSpace(config.After)
|| string.IsNullOrWhiteSpace(config.Version))
{
return null;
}
return config;
}
catch (Exception ex)
{
Console.WriteLine($"[ERROR] Failed to read or parse config file: {ex.Message}");
return null;
}
}