Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Add progress display of saving
Browse files Browse the repository at this point in the history
  • Loading branch information
aianlinb authored Sep 26, 2020
1 parent b9fead5 commit a5129f8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
17 changes: 4 additions & 13 deletions VisualBundle/ItemModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace VisualBundle
Expand Down Expand Up @@ -38,12 +29,12 @@ public virtual string Path
}
public void AddChildItem(ItemModel Item)
{
this.ChildItems.Add(Item);
ChildItems.Add(Item);
Item.Parent = this;
}
public ItemModel GetChildItem(string Name)
{
return this.ChildItems.FirstOrDefault(ItemCollection => ItemCollection.Name == Name);
return ChildItems.FirstOrDefault(ItemCollection => ItemCollection.Name == Name);
}
}
public class FolderModel : ItemModel
Expand Down Expand Up @@ -82,4 +73,4 @@ public FileModel(string name) : this()
Name = name;
}
}
}
}
4 changes: 2 additions & 2 deletions VisualBundle/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window x:Class="VisualBundle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="VisualBundle" Height="450" Width="750" Loaded="OnLoaded" Closing="OnWindowClosing">
Title="VisualBundle" Height="480" Width="800" Loaded="OnLoaded" Closing="OnWindowClosing">
<Window.Resources>
<HierarchicalDataTemplate x:Key="FileViewItemTemplate" DataType="x:Type self:ItemModel" ItemsSource="{Binding ChildItems}">
<StackPanel Orientation="Horizontal">
Expand All @@ -18,7 +18,7 @@
<TextBox x:Name="offsetView" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="100" Margin="310,6,0,0"/>
<TextBox x:Name="sizeView" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="100" Margin="460,6,0,0"/>
<TextBox x:Name="noView" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="100" Margin="610,6,0,0"/>
<TreeView x:Name="View2" ItemTemplate="{StaticResource FileViewItemTemplate}" SelectedItemChanged="OnTreeView2SelectedChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="250,35,230,0"/>
<TreeView x:Name="View2" ItemTemplate="{StaticResource FileViewItemTemplate}" SelectedItemChanged="OnTreeView2SelectedChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="250,35,235,0"/>
<TextBlock HorizontalAlignment="Right" TextWrapping="Wrap" Text="Offset (Bundle):" VerticalAlignment="Top" Margin="0,60,130,0"/>
<TextBlock HorizontalAlignment="Right" TextWrapping="Wrap" Text="Offset (Index):" VerticalAlignment="Top" Margin="0,90,130,0"/>
<TextBlock HorizontalAlignment="Right" TextWrapping="Wrap" Text="FileSize:" VerticalAlignment="Top" Margin="0,120,130,0"/>
Expand Down
27 changes: 24 additions & 3 deletions VisualBundle/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Media;

Expand Down Expand Up @@ -94,10 +95,12 @@ private ItemModel GetSelectedBundle()
{
return (ItemModel)View1.SelectedItem;
}

private ItemModel GetSelectedFile()
{
return (ItemModel)View2.SelectedItem;
}

private void OnTreeView1SelectedChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
var tvi = GetSelectedBundle();
Expand Down Expand Up @@ -334,6 +337,7 @@ private void MoveF(BundleRecord br)
{
if (MessageBox.Show("Are you sure you want to move " + ic.Hashes[moveF.Hash] + " into " + br.Name + "?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
{
MessageLabel.Text = "Moving . . .";
changed.Add(moveF.bundleRecord);
changed.Add(br);
moveF.Move(br);
Expand All @@ -349,6 +353,7 @@ private void MoveD(BundleRecord br)
{
if (MessageBox.Show("Are you sure you want to move directory " + moveD.Name + " into " + br.Name + "?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
{
MessageLabel.Text = "Moving . . .";
MessageBox.Show("Moved " + MoveDir(moveD.ChildItems, br).ToString() + " Files", "Done");
changed.Add(br);
ButtonSave.IsEnabled = true;
Expand Down Expand Up @@ -402,9 +407,23 @@ private void OnProcessExit(object sender, EventArgs e)
private void OnButtonSaveClick(object sender, RoutedEventArgs e)
{
ButtonSave.IsEnabled = false;
foreach (var br in changed)
br.Save(br.Name);
ic.Save("_.index.bin");
var sw = new SavingWindow();
var t = new Thread(new ThreadStart(() => {
var i = 1;
var text = "Saving {0} / " + (changed.Count + 1).ToString() + " bundles . . .";
foreach (var br in changed)
{
Dispatcher.Invoke(() => { sw.TextBlock1.Text = string.Format(text, i); });
br.Save(br.Name);
i++;
}
Dispatcher.Invoke(() => { sw.TextBlock1.Text = string.Format(text, i); });
ic.Save("_.index.bin");
sw.Closing -= sw.OnClosing;
Dispatcher.Invoke(sw.Close);
}));
t.Start();
sw.ShowDialog();
MessageBox.Show("Success saved!" + Environment.NewLine + changed.Count.ToString() + " bundle files changed", "Done");
changed.Clear();
}
Expand Down Expand Up @@ -456,6 +475,7 @@ private void ButtonReplaceAllClick(object sender, RoutedEventArgs e)
}
}
}

private HashSet<BundleRecord> GetLoadedBundleRecordAll()
{
var bundles = new HashSet<BundleRecord>();
Expand Down Expand Up @@ -484,6 +504,7 @@ private HashSet<BundleRecord> GetLoadedBundleRecordAll()
return bundles;

}

private OpenFileDialog OpenBundle2Dialog()
{
var ofd = new OpenFileDialog()
Expand Down
7 changes: 7 additions & 0 deletions VisualBundle/VisualBundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
<Compile Include="ErrorWindow.xaml.cs">
<DependentUpon>ErrorWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SavingWindow.xaml.cs">
<DependentUpon>SavingWindow.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -109,6 +112,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SavingWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down

0 comments on commit a5129f8

Please sign in to comment.