diff --git a/LazyDisYTUnloker/App.config b/LazyDisYTUnloker/App.config deleted file mode 100644 index 9e3f5d0..0000000 --- a/LazyDisYTUnloker/App.config +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/LazyDisYTUnloker/FilesAndDirectories.cs b/LazyDisYTUnloker/FilesAndDirectories.cs index 4731fd7..d424810 100644 --- a/LazyDisYTUnloker/FilesAndDirectories.cs +++ b/LazyDisYTUnloker/FilesAndDirectories.cs @@ -8,31 +8,24 @@ internal static class FilesAndDirectories { internal static MainForm Form { get; set; } = null!; - internal const string MainZapretDirectory = "zapret-win-bundle-master"; - internal const string WinwsDirectory = "zapret-winws"; - private const string _discordDomainsListFile = "list-discord.txt"; - private const string _youtubeDomainsListFile = "list-youtube.txt"; - - private static List _discordDomains = new List(ConfigurationManager.AppSettings["discordDomains"].Split('\n')); - private static List _youtubeDomains = new List(ConfigurationManager.AppSettings["youtubeDomains"].Split('\n')); + internal const string _mainZapretDirectory = "zapret-win-bundle-master"; + internal const string _winwsDirectory = "zapret-winws"; internal static void SetupDirectory() { - Directory.CreateDirectory(MainZapretDirectory); + Directory.CreateDirectory(_mainZapretDirectory); } internal static bool IsZapretBundleDirectoriesLoaded() { - Form.ChangeDiscordDomainsCountLabel(_discordDomains.Count); - Form.ChangeYouTubeDomainsCountLabel(_youtubeDomains.Count); - if (Directory.Exists(MainZapretDirectory) && Directory.GetDirectories(MainZapretDirectory).Count() == 5) + if (Directory.Exists(_mainZapretDirectory) && Directory.GetDirectories(_mainZapretDirectory).Count() == 5) { Form.ChangeZapretBundleStatus("готов к работе"); return true; } Form.ChangeZapretBundleStatus("не загружен и не готов к работе"); - if (Directory.Exists(MainZapretDirectory)) - Directory.Delete(MainZapretDirectory, true); + if (Directory.Exists(_mainZapretDirectory)) + Directory.Delete(_mainZapretDirectory, true); return false; } @@ -47,28 +40,15 @@ internal static async Task DownloadUnpackAndSetupZapret() using (MemoryStream ms = new MemoryStream(data)) using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read)) archive.ExtractToDirectory(Directory.GetCurrentDirectory()); - if (!File.Exists($"{MainZapretDirectory}\\{WinwsDirectory}\\{_discordDomainsListFile}")) - CreateDiscordDomainsFile(); - if (!File.Exists($"{MainZapretDirectory}\\{WinwsDirectory}\\{_youtubeDomainsListFile}")) - CreateYouTubeDomainsFile(); return true; } catch { - Form.ChangeZapretBundleStatus("не получилось загрузить или распаковать :("); + Form.ChangeZapretBundleStatus("не получилось загрузить или распаковать Zapret :("); return false; } - - } - - private static void CreateDiscordDomainsFile() - { - File.WriteAllLines($"{MainZapretDirectory}\\{WinwsDirectory}\\{_discordDomainsListFile}", _discordDomains); } - private static void CreateYouTubeDomainsFile() - { - File.WriteAllLines($"{MainZapretDirectory}\\{WinwsDirectory}\\{_youtubeDomainsListFile}", _youtubeDomains); - } + internal static string GetWinwsPath => $"{_mainZapretDirectory}\\{_winwsDirectory}"; } } diff --git a/LazyDisYTUnloker/LazyDisYTUnloker.csproj b/LazyDisYTUnloker/LazyDisYTUnloker.csproj index c3f8eaa..300e09d 100644 --- a/LazyDisYTUnloker/LazyDisYTUnloker.csproj +++ b/LazyDisYTUnloker/LazyDisYTUnloker.csproj @@ -14,10 +14,4 @@ - - - PreserveNewest - - - \ No newline at end of file diff --git a/LazyDisYTUnloker/MainForm.Designer.cs b/LazyDisYTUnloker/MainForm.Designer.cs index b20f1b6..81c18c7 100644 --- a/LazyDisYTUnloker/MainForm.Designer.cs +++ b/LazyDisYTUnloker/MainForm.Designer.cs @@ -85,27 +85,27 @@ private void InitializeComponent() YouTubeDomainsCountLabel.AutoSize = true; YouTubeDomainsCountLabel.Location = new Point(6, 50); YouTubeDomainsCountLabel.Name = "YouTubeDomainsCountLabel"; - YouTubeDomainsCountLabel.Size = new Size(187, 15); + YouTubeDomainsCountLabel.Size = new Size(157, 15); YouTubeDomainsCountLabel.TabIndex = 2; - YouTubeDomainsCountLabel.Text = "Число доменов YouTube: {count}"; + YouTubeDomainsCountLabel.Text = "Число доменов YouTube: ..."; // // DiscordDomainsCountLabel // DiscordDomainsCountLabel.AutoSize = true; DiscordDomainsCountLabel.Location = new Point(6, 34); DiscordDomainsCountLabel.Name = "DiscordDomainsCountLabel"; - DiscordDomainsCountLabel.Size = new Size(181, 15); + DiscordDomainsCountLabel.Size = new Size(151, 15); DiscordDomainsCountLabel.TabIndex = 1; - DiscordDomainsCountLabel.Text = "Число доменов Discord: {count}"; + DiscordDomainsCountLabel.Text = "Число доменов Discord: ..."; // // BundleStatusLabel // BundleStatusLabel.AutoSize = true; BundleStatusLabel.Location = new Point(6, 18); BundleStatusLabel.Name = "BundleStatusLabel"; - BundleStatusLabel.Size = new Size(148, 15); + BundleStatusLabel.Size = new Size(118, 15); BundleStatusLabel.TabIndex = 0; - BundleStatusLabel.Text = "Состояние Zapret: {status}"; + BundleStatusLabel.Text = "Состояние Zapret: ..."; // // Status // diff --git a/LazyDisYTUnloker/MainForm.cs b/LazyDisYTUnloker/MainForm.cs index 5dadd09..a5c0ad7 100644 --- a/LazyDisYTUnloker/MainForm.cs +++ b/LazyDisYTUnloker/MainForm.cs @@ -29,7 +29,7 @@ private async Task CheckFilesAndSetup() FilesAndDirectories.SetupDirectory(); ChangeStatus(" ..."); - if (await FilesAndDirectories.DownloadUnpackAndSetupZapret() && FilesAndDirectories.IsZapretBundleDirectoriesLoaded() && await Strategies.UpdateStrategies(true)) + if (await FilesAndDirectories.DownloadUnpackAndSetupZapret() && FilesAndDirectories.IsZapretBundleDirectoriesLoaded() && await Strategies.GetStrategies(true)) { ChangeZapretBundleStatus(" "); BeginInvoke(() => @@ -49,7 +49,7 @@ private async Task CheckFilesAndSetup() } else { - if (await Strategies.UpdateStrategies(false)) + if (await Strategies.GetStrategies(false)) { BeginInvoke(() => { @@ -133,7 +133,7 @@ private async void UpdateStrategiesButton_Click(object sender, EventArgs e) MainButton.Enabled = false; UpdateStrategiesButton.Enabled = false; }); - if (await Strategies.UpdateStrategies(true)) + if (await Strategies.GetStrategies(true)) { BeginInvoke(() => { diff --git a/LazyDisYTUnloker/ProcessManager.cs b/LazyDisYTUnloker/ProcessManager.cs index 04837d1..2104c5d 100644 --- a/LazyDisYTUnloker/ProcessManager.cs +++ b/LazyDisYTUnloker/ProcessManager.cs @@ -11,8 +11,8 @@ internal static bool RunStrategies() { try { - _discordUnlockProcess = Process.Start(new ProcessStartInfo() { FileName = $"{FilesAndDirectories.MainZapretDirectory}\\{FilesAndDirectories.WinwsDirectory}\\winws.exe", Arguments = Strategies.DiscordStrategy.Replace("[winwsdir]", $"{FilesAndDirectories.MainZapretDirectory}\\{FilesAndDirectories.WinwsDirectory}"), CreateNoWindow = true, UseShellExecute = false }); - _youtubeUnlockProcess = Process.Start(new ProcessStartInfo() { FileName = $"{FilesAndDirectories.MainZapretDirectory}\\{FilesAndDirectories.WinwsDirectory}\\winws.exe", Arguments = Strategies.YouTubeStrategy.Replace("[winwsdir]", $"{FilesAndDirectories.MainZapretDirectory}\\{FilesAndDirectories.WinwsDirectory}"), CreateNoWindow = true, UseShellExecute = false }); + _discordUnlockProcess = Process.Start(new ProcessStartInfo() { FileName = $"{FilesAndDirectories._mainZapretDirectory}\\{FilesAndDirectories._winwsDirectory}\\winws.exe", Arguments = Strategies.DiscordStrategy.Replace("[winwsdir]", $"{FilesAndDirectories._mainZapretDirectory}\\{FilesAndDirectories._winwsDirectory}"), CreateNoWindow = true, UseShellExecute = false }); + _youtubeUnlockProcess = Process.Start(new ProcessStartInfo() { FileName = $"{FilesAndDirectories._mainZapretDirectory}\\{FilesAndDirectories._winwsDirectory}\\winws.exe", Arguments = Strategies.YouTubeStrategy.Replace("[winwsdir]", $"{FilesAndDirectories._mainZapretDirectory}\\{FilesAndDirectories._winwsDirectory}"), CreateNoWindow = true, UseShellExecute = false }); return true; } catch (Exception ex) diff --git a/LazyDisYTUnloker/Strategies.cs b/LazyDisYTUnloker/Strategies.cs index 065c30a..9cd4d4d 100644 --- a/LazyDisYTUnloker/Strategies.cs +++ b/LazyDisYTUnloker/Strategies.cs @@ -5,28 +5,36 @@ internal static class Strategies internal static string DiscordStrategy { get; private set; } = null!; internal static string YouTubeStrategy { get; private set; } = null!; - internal static async Task UpdateStrategies(bool update) + internal static async Task GetStrategies(bool update) { try { if (!update) { - if (File.Exists("dsstrat.txt") && File.Exists("ytstrat.txt")) + if (File.Exists("dsstrat.txt") && File.Exists("ytstrat.txt") && File.Exists($"{FilesAndDirectories.GetWinwsPath}\\list-youtube.txt") && File.Exists($"{FilesAndDirectories.GetWinwsPath}\\list-discord.txt")) { DiscordStrategy = File.ReadAllText("dsstrat.txt"); YouTubeStrategy = File.ReadAllText("ytstrat.txt"); + FilesAndDirectories.Form.ChangeLastStrategiesUpdateDate(new FileInfo("dsstrat.txt").LastWriteTime); + FilesAndDirectories.Form.ChangeDiscordDomainsCountLabel(File.ReadAllLines($"{FilesAndDirectories.GetWinwsPath}\\list-discord.txt").Count()); + FilesAndDirectories.Form.ChangeYouTubeDomainsCountLabel(File.ReadAllLines($"{FilesAndDirectories.GetWinwsPath}\\list-youtube.txt").Count()); return true; } - return await UpdateStrategies(true); + return await GetStrategies(true); } using (HttpClient client = new HttpClient()) { - DiscordStrategy = await client.GetStringAsync("https://raw.githubusercontent.com/WutADude/LazyDiscordAndYouTubeUnlocker/refs/heads/master/Dscord%20Zapret%20strategy.txt"); - YouTubeStrategy = await client.GetStringAsync("https://raw.githubusercontent.com/WutADude/LazyDiscordAndYouTubeUnlocker/refs/heads/master/YouTube%20Zapret%20strategy.txt"); + DiscordStrategy = await client.GetStringAsync("https://raw.githubusercontent.com/WutADude/LazyDiscordAndYouTubeUnlocker/refs/heads/master/Strategies/Dscord%20Zapret%20strategy.txt"); + YouTubeStrategy = await client.GetStringAsync("https://raw.githubusercontent.com/WutADude/LazyDiscordAndYouTubeUnlocker/refs/heads/master/Strategies/YouTube%20Zapret%20strategy.txt"); + File.WriteAllText($"{FilesAndDirectories.GetWinwsPath}\\list-discord.txt", await client.GetStringAsync("https://raw.githubusercontent.com/WutADude/LazyDiscordAndYouTubeUnlocker/refs/heads/master/Hosts/DiscordHosts.txt")); //TODO: Допилить парс хостов + File.WriteAllText($"{FilesAndDirectories.GetWinwsPath}\\list-youtube.txt", await client.GetStringAsync("https://raw.githubusercontent.com/WutADude/LazyDiscordAndYouTubeUnlocker/refs/heads/master/Hosts/YouTubeHosts.txt")); File.WriteAllText("dsstrat.txt", DiscordStrategy); File.WriteAllText("ytstrat.txt", YouTubeStrategy); + } - + FilesAndDirectories.Form.ChangeLastStrategiesUpdateDate(new FileInfo("dsstrat.txt").LastWriteTime); + FilesAndDirectories.Form.ChangeDiscordDomainsCountLabel(File.ReadAllLines($"{FilesAndDirectories.GetWinwsPath}\\list-discord.txt").Count()); + FilesAndDirectories.Form.ChangeYouTubeDomainsCountLabel(File.ReadAllLines($"{FilesAndDirectories.GetWinwsPath}\\list-youtube.txt").Count()); return true; } catch (Exception ex) @@ -36,11 +44,6 @@ internal static async Task UpdateStrategies(bool update) $"{ex.Message}", "Ошибка при получении/обновлении стратегий", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } - finally - { - if (File.Exists("dsstrat.txt")) - FilesAndDirectories.Form.ChangeLastStrategiesUpdateDate(new FileInfo("dsstrat.txt").LastWriteTime); - } } } }