Skip to content

Commit

Permalink
- Semantical changes
Browse files Browse the repository at this point in the history
- Decrease nesting
  • Loading branch information
KoalaBear84 committed Oct 31, 2024
1 parent f9f457d commit 7361015
Show file tree
Hide file tree
Showing 14 changed files with 1,852 additions and 1,581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Apis.Drive.v3" Version="1.68.0.3490" />
<PackageReference Include="Google.Apis.Drive.v3" Version="1.68.0.3574" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
52 changes: 30 additions & 22 deletions src/OpenDirectoryDownloader/BrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public async Task InitializeAsync()

try
{
if (!browserFetcher.GetInstalledBrowsers().Any(x => x.BuildId == Chrome.DefaultBuildId))
if (browserFetcher.GetInstalledBrowsers().All(x => x.BuildId != Chrome.DefaultBuildId))
{
Program.Logger.Warning("Downloading browser... First time it can take a while, depending on your internet connection.");
InstalledBrowser installedBrowser = await browserFetcher.DownloadAsync(Chrome.DefaultBuildId);
Expand All @@ -164,9 +164,9 @@ public async Task InitializeAsync()
Browser = await puppeteerExtra.LaunchAsync(new LaunchOptions
{
Headless = false,
Args = new[] { "--no-sandbox", "--disable-setuid-sandbox", $"--user-agent=\"{Constants.UserAgent.Chrome}\"" },
Args = ["--no-sandbox", "--disable-setuid-sandbox", $"--user-agent=\"{Constants.UserAgent.Chrome}\""],
DefaultViewport = null,
IgnoreHTTPSErrors = true
AcceptInsecureCerts = true
});

Program.Logger.Information("Started browser with PID {processId}", Browser.Process.Id);
Expand Down Expand Up @@ -311,7 +311,7 @@ private void Page_Error(object sender, ErrorEventArgs e)
WriteDebugInfo($"Page_Error: {e.Error}");
}

private async void Page_FrameAttached(object sender, FrameEventArgs e)
private void Page_FrameAttached(object sender, FrameEventArgs e)
{
WriteDebugInfo($"Page_FrameAttached: {e.Frame.Url}");
}
Expand Down Expand Up @@ -379,23 +379,29 @@ private void Page_Response(object sender, ResponseCreatedEventArgs e)

string theCookie = cookieHeader.Split('\n').FirstOrDefault(cookie => cookie.StartsWith(CloudflareClearanceKey));

if (theCookie != null)
if (theCookie == null)
{
CookieContainer.SetCookies(new Uri(baseUrl), theCookie);
return;
}

if (CloudFlare)
{
Cookie cloudflareClearance = CookieContainer.GetCookies(new Uri(baseUrl)).FirstOrDefault(c => c.Name == CloudflareClearanceKey);
CookieContainer.SetCookies(new Uri(baseUrl), theCookie);

if (cloudflareClearance != null)
{
WriteDebugInfo($"Cloudflare clearance cookie found: {cloudflareClearance.Value}");
if (!CloudFlare)
{
return;
}

OK = true;
CancellationTokenSource.Cancel();
}
}
Cookie cloudflareClearance = CookieContainer.GetCookies(new Uri(baseUrl)).FirstOrDefault(c => c.Name == CloudflareClearanceKey);

if (cloudflareClearance == null)
{
return;
}

WriteDebugInfo($"Cloudflare clearance cookie found: {cloudflareClearance.Value}");

OK = true;
CancellationTokenSource.Cancel();
}
else
{
Expand Down Expand Up @@ -425,15 +431,17 @@ private void CheckCloudflareCookie()

CookieParam cloudflareClearanceCookie = cookieParams.FirstOrDefault(cookie => cookie.Name.StartsWith(CloudflareClearanceKey));

if (cloudflareClearanceCookie is not null)
if (cloudflareClearanceCookie is null)
{
WriteDebugInfo($"Cloudflare clearance cookie found: {cloudflareClearanceCookie.Value}");
return;
}

AddCookiesToContainer(CookieContainer, cookieParams);
WriteDebugInfo($"Cloudflare clearance cookie found: {cloudflareClearanceCookie.Value}");

OK = true;
CancellationTokenSource.Cancel();
}
AddCookiesToContainer(CookieContainer, cookieParams);

OK = true;
CancellationTokenSource.Cancel();
}
catch
{
Expand Down
44 changes: 24 additions & 20 deletions src/OpenDirectoryDownloader/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public class Command
/// </summary>
internal static void SetConsoleProperties()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WindowWidth = Math.Min(170, Console.LargestWindowWidth);
Console.WindowHeight = Math.Min(34, Console.LargestWindowHeight);
return;
}

Console.WindowWidth = Math.Min(170, Console.LargestWindowWidth);
Console.WindowHeight = Math.Min(34, Console.LargestWindowHeight);
}

internal static void ShowInfoAndCommands()
Expand Down Expand Up @@ -253,28 +255,30 @@ private static void SetClipboard(string value)
{
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
try
return;
}

try
{
Process clipboardExecutable = new()
{
Process clipboardExecutable = new()
StartInfo = new ProcessStartInfo
{
StartInfo = new ProcessStartInfo
{
RedirectStandardInput = true,
FileName = @"wl-copy",
}
};
RedirectStandardInput = true,
FileName = @"wl-copy",
}
};

clipboardExecutable.Start();
clipboardExecutable.StandardInput.Write(value);
clipboardExecutable.StandardInput.Close();
clipboardExecutable.Start();
clipboardExecutable.StandardInput.Write(value);
clipboardExecutable.StandardInput.Close();

return;
}
catch
{
}
return;
}
catch
{
}
}
}
Loading

0 comments on commit 7361015

Please sign in to comment.