Skip to content

Commit

Permalink
v.1.1.1
Browse files Browse the repository at this point in the history
* Added a progress bar to updating process
  • Loading branch information
Prevter committed Jul 27, 2022
1 parent 61fe09c commit 8d1c665
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
57 changes: 57 additions & 0 deletions FloatTool/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,70 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace FloatTool
{
// Taken from here:
// https://stackoverflow.com/a/46497896/16349466
public static class StreamExtensions
{
public static async Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<long> progress = null, CancellationToken cancellationToken = default)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (!source.CanRead)
throw new ArgumentException("Has to be readable", nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (!destination.CanWrite)
throw new ArgumentException("Has to be writable", nameof(destination));
if (bufferSize < 0)
throw new ArgumentOutOfRangeException(nameof(bufferSize));

var buffer = new byte[bufferSize];
long totalBytesRead = 0;
int bytesRead;
while ((bytesRead = await source.ReadAsync(buffer, cancellationToken).ConfigureAwait(false)) != 0)
{
await destination.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken).ConfigureAwait(false);
totalBytesRead += bytesRead;
progress?.Report(totalBytesRead);
}
}
}

public static class HttpClientExtensions
{
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<float> progress = null, CancellationToken cancellationToken = default)
{
// Get the http headers first to examine the content length
using var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
var contentLength = response.Content.Headers.ContentLength;

using var download = await response.Content.ReadAsStreamAsync(cancellationToken);

// Ignore progress reporting when no progress reporter was
// passed or when the content length is unknown
if (progress == null || !contentLength.HasValue)
{
await download.CopyToAsync(destination, cancellationToken);
return;
}

// Convert absolute progress (bytes downloaded) into relative progress (0% - 100%)
var relativeProgress = new Progress<long>(totalBytes => progress.Report((float)totalBytes / contentLength.Value));
// Use extension method to report progress while downloading
await download.CopyToAsync(destination, 81920, relativeProgress, cancellationToken);
progress.Report(1);
}
}

public static class StringExtensions
{
public static string FirstCharToUpper(this string input) =>
Expand Down
2 changes: 1 addition & 1 deletion FloatTool/FloatTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://prevter.github.io/FloatTool</PackageProjectUrl>
<RepositoryUrl>https://github.com/Prevter/FloatTool</RepositoryUrl>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>1.1.0</AssemblyVersion>
<AssemblyVersion>1.1.1</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<ApplicationIcon>Assets\Icon.ico</ApplicationIcon>
<DebugType>embedded</DebugType>
Expand Down
4 changes: 3 additions & 1 deletion FloatTool/Views/UpdateWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Button Content="{DynamicResource m_Update}" Grid.Column="2" Style="{DynamicResource MainButtonStyle}" Click="UpdateButtonClick"/>
<Button Content="{DynamicResource m_Update}" Grid.Column="2" Style="{DynamicResource MainButtonStyle}" Click="UpdateButtonClick" x:Name="UpdateButton"/>
<Button Content="{DynamicResource m_Later}" Grid.Column="1" Style="{DynamicResource MainButtonStyle}" Margin="2,0" Click="LaterButtonClick"/>
<Button Content="{DynamicResource m_DoNotAsk}" Grid.Column="0" Style="{DynamicResource MainButtonStyle}" Click="DoNotAskButtonClick"/>

<ProgressBar Visibility="Hidden" Grid.Column="0" Grid.ColumnSpan="2" Background="{DynamicResource ProgressBackground}" BorderThickness="0" Foreground="{DynamicResource ProgressFill}" x:Name="DownloadProgress"/>
</Grid>
</Grid>
</Grid>
Expand Down
13 changes: 10 additions & 3 deletions FloatTool/Views/UpdateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,23 @@ private void DoNotAskButtonClick(object sender, RoutedEventArgs e)

private void UpdateButtonClick(object sender, RoutedEventArgs e)
{
UpdateButton.IsEnabled = false;
DownloadProgress.Visibility = Visibility.Visible;
string archiveUrl = UpdateResult.Assets[0].BrowserDownloadUrl;
Task.Run(async () =>
{
// Download the archive
using HttpClient client = new();
using (var s = await client.GetStreamAsync(archiveUrl))
var progress = new Progress<float>(value =>
{
using var fs = new FileStream("update.zip", FileMode.CreateNew);
await s.CopyToAsync(fs);
DownloadProgress.Dispatcher.Invoke(() => DownloadProgress.Value = value * 100);
});

using (var file = new FileStream("update.zip", FileMode.Create, FileAccess.Write, FileShare.None))
{
await client.DownloadAsync(archiveUrl, file, progress);
}

// Rename all locked files to .old
string folderPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
foreach (string file in Directory.GetFiles(folderPath, "*", SearchOption.TopDirectoryOnly))
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
![Program Working](https://github.com/Prevter/FloatTool/blob/master/doc/program.png?raw=true)

This app allows you to quickly search combinations to craft skins in CS:GO with (almost) any float you want. All you have to do is set some search settings, wait a bit and all you have to do next is to buy skins from marketplace, that the app found to be needed.
This is probably the fastest app you can find, as it can achieve more than 10,000,000 combinations per second on a i9-9900K.
This is probably the fastest app you can find, as it can achieve more than 15,000,000 combinations per second on an old Ryzen 5 2600.

## Getting Started

Expand All @@ -39,6 +39,18 @@ This is probably the fastest app you can find, as it can achieve more than 10,00
_Please see [Documentation](https://prevter.github.io/FloatTool/tutorial.html) for complete tutorial in usage_

## Version History
* 1.1.1
* Added a progress bar to updating process
* 1.1.0
* Minor bug fixes
* Small optimizations
* Added CZ75, P250, SSG 08, Tec-9 and USP-S to list (haven't realized until now)
* Fixed all warnings and messages in VS
* Added search filter check, it'l show a warning if you entered incorrect settings
* If you press F4, it will open steam marketplace for current skin
* 1.0.2
* Added Recoil case
* You can now press F3 to open current collection on CSGOStash
* 1.0.1
* Fixed critical bug that showed incorrect combinations.
* Added new collections:
Expand Down

0 comments on commit 8d1c665

Please sign in to comment.