Add solution and project files; introduce .gitignore and clean IDE/build artifacts
This commit is contained in:
commit
be5a4e9fa7
10 changed files with 270 additions and 0 deletions
72
MainWindow.xaml.cs
Normal file
72
MainWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Ookii.Dialogs.Wpf; // ← add this
|
||||
|
||||
namespace MossyUpdater
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Browse_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new VistaFolderBrowserDialog
|
||||
{
|
||||
Description = "Select a destination folder",
|
||||
UseDescriptionForTitle = true
|
||||
};
|
||||
|
||||
// ShowDialog returns true if the user clicked OK
|
||||
if (dlg.ShowDialog() == true)
|
||||
FolderTextBox.Text = dlg.SelectedPath;
|
||||
}
|
||||
|
||||
private async void Download_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string url = UrlTextBox.Text.Trim();
|
||||
string folder = FolderTextBox.Text.Trim();
|
||||
string filename = FilenameTextBox.Text.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(url)
|
||||
|| string.IsNullOrEmpty(folder)
|
||||
|| string.IsNullOrEmpty(filename))
|
||||
{
|
||||
StatusTextBlock.Text = "Please fill in all fields.";
|
||||
StatusTextBlock.Foreground = System.Windows.Media.Brushes.Red;
|
||||
return;
|
||||
}
|
||||
|
||||
string fullPath = Path.Combine(folder, filename);
|
||||
|
||||
try
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
var data = await client.GetByteArrayAsync(url);
|
||||
await File.WriteAllBytesAsync(fullPath, data);
|
||||
|
||||
UnblockFile(fullPath);
|
||||
|
||||
StatusTextBlock.Text = $"Downloaded and unblocked:\n{fullPath}";
|
||||
StatusTextBlock.Foreground = System.Windows.Media.Brushes.Green;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusTextBlock.Text = $"Error: {ex.Message}";
|
||||
StatusTextBlock.Foreground = System.Windows.Media.Brushes.Red;
|
||||
}
|
||||
}
|
||||
|
||||
private void UnblockFile(string path)
|
||||
{
|
||||
var zone = path + ":Zone.Identifier";
|
||||
if (File.Exists(zone))
|
||||
File.Delete(zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue