Browse Source

WinRT: complete downloading feature

Lou Yihua 6 years ago
parent
commit
0d2e05edaf

+ 6 - 12
winrt/SDLPal.Common/DownloadDialog.xaml

@@ -13,13 +13,9 @@
     MinHeight="0" MinWidth="0"
     Closing="OnClosing" Opened="OnOpened" SizeChanged="OnSizeChanged">
 
-    <Grid x:Name="gridMain">
-        <Grid.RowDefinitions>
-            <RowDefinition x:Name="gridRow1" />
-            <RowDefinition Height="48" />
-        </Grid.RowDefinitions>
-        <WebView x:Name="wvDownloadPage" Grid.Row="0" NavigationStarting="OnNavigateStart" DOMContentLoaded="OnDOMContentLoaded" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto" />
-        <Grid x:Name="gridURL" HorizontalAlignment="Stretch" Grid.Row="0">
+    <StackPanel Orientation="Vertical">
+        <WebView x:Name="wvDownloadPage" NavigationStarting="OnNavigateStart" DOMContentLoaded="OnDOMContentLoaded" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto" />
+        <Grid x:Name="gridURL" HorizontalAlignment="Stretch">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition />
                 <ColumnDefinition Width="Auto" />
@@ -27,9 +23,7 @@
             <TextBox x:Name="tbURL" x:Uid="URL" Header="游戏资源 Zip 压缩包地址" Grid.Column="0" HorizontalAlignment="Stretch" PlaceholderText="http://host.name/path/to/archive.zip" />
             <Button x:Name="btnGoTo" Grid.Column="1" VerticalAlignment="Bottom" Content="=>" Click="OnClick" />
         </Grid>
-        <StackPanel x:Name="spProgress" Orientation="Vertical" Grid.Row="1" Padding="0,4,0,4">
-            <ProgressBar x:Name="pbDownload" HorizontalAlignment="Stretch" Height="12" Margin="0,4,0,0" />
-            <TextBlock x:Name="tbProgress" HorizontalAlignment="Right" Height="20" Text="0 / 0" />
-        </StackPanel>
-    </Grid>
+        <ProgressBar x:Name="pbDownload" HorizontalAlignment="Stretch" Height="12" Margin="0,8,0,4" />
+        <TextBlock x:Name="tbProgress" HorizontalAlignment="Right" Height="20" Text="0 / 0" Margin="0,4,0,4" />
+    </StackPanel>
 </ContentDialog>

+ 16 - 18
winrt/SDLPal.Common/DownloadDialog.xaml.cpp

@@ -49,22 +49,17 @@ struct zip_file
 };
 
 SDLPal::DownloadDialog::DownloadDialog(Windows::ApplicationModel::Resources::ResourceLoader^ ldr, StorageFolder^ folder, IRandomAccessStream^ stream, Platform::String^ msgfile, double w, double h, bool from_url)
-	: m_stream(stream), m_Closable(false), m_Downloading(false), m_totalBytes(0), m_resLdr(ldr), m_folder(folder), m_width(w), m_height(h), m_msgfile(msgfile)
+	: m_stream(stream), m_Closable(false), m_Downloading(false), m_totalBytes(0), m_resLdr(ldr), m_folder(folder), m_width(w), m_height(h), m_msgfile(msgfile), m_FromURL(from_url)
 {
 	InitializeComponent();
 
 	this->MaxWidth = w;
 	this->MaxHeight = h;
 	this->PrimaryButtonText = m_resLdr->GetString("ButtonBack");
-	spProgress->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
-	if (from_url)
-	{
-		wvDownloadPage->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
-	}
-	else
-	{
-		gridURL->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
-	}
+	pbDownload->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
+	tbProgress->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
+	wvDownloadPage->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
+	gridURL->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
 }
 
 Platform::String^ SDLPal::DownloadDialog::FormatProgress()
@@ -88,12 +83,12 @@ Platform::String^ SDLPal::DownloadDialog::FormatProgress()
 
 void SDLPal::DownloadDialog::DoDownload(Platform::String^ url)
 {
-	this->FullSizeDesired = false;
-	gridRow1->Height = 0;
 	wvDownloadPage->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
 	gridURL->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
-	spProgress->Visibility = Windows::UI::Xaml::Visibility::Visible;
-	this->MaxHeight = 128 + 48;
+	pbDownload->Visibility = Windows::UI::Xaml::Visibility::Visible;
+	tbProgress->Visibility = Windows::UI::Xaml::Visibility::Visible;
+	this->FullSizeDesired = false;
+	this->MaxHeight = 232;
 	this->Title = m_resLdr->GetString("DialogTitle");
 	this->PrimaryButtonText = m_resLdr->GetString("ButtonStop");
 	this->UpdateLayout();
@@ -303,10 +298,15 @@ void SDLPal::DownloadDialog::OnClosing(Windows::UI::Xaml::Controls::ContentDialo
 
 void SDLPal::DownloadDialog::OnOpened(Windows::UI::Xaml::Controls::ContentDialog^ sender, Windows::UI::Xaml::Controls::ContentDialogOpenedEventArgs^ args)
 {
-	if (wvDownloadPage->Visibility == Windows::UI::Xaml::Visibility::Visible)
+	if (m_FromURL)
 	{
+		gridURL->Visibility = Windows::UI::Xaml::Visibility::Visible;
+		UpdateLayout();
+	}
+	else
+	{
+		wvDownloadPage->Visibility = Windows::UI::Xaml::Visibility::Visible;
 		this->FullSizeDesired = true;
-		gridRow1->Height = m_height - 128;
 		wvDownloadPage->Width = m_width - 48;
 		wvDownloadPage->Height = m_height - 128;
 		UpdateLayout();
@@ -359,8 +359,6 @@ void SDLPal::DownloadDialog::OnSizeChanged(Platform::Object^ sender, Windows::UI
 {
 	if (wvDownloadPage->Visibility == Windows::UI::Xaml::Visibility::Visible)
 	{
-		this->FullSizeDesired = true;
-		gridRow1->Height = e->NewSize.Height - 128;
 		wvDownloadPage->Width = e->NewSize.Width - 48;
 		wvDownloadPage->Height = e->NewSize.Height - 128;
 		UpdateLayout();

+ 1 - 1
winrt/SDLPal.Common/DownloadDialog.xaml.h

@@ -24,7 +24,7 @@ namespace SDLPal
 		Platform::String^ m_msgfile;
 		double m_width, m_height;
 		uint64_t m_totalBytes;
-		bool m_Closable, m_Downloading;
+		bool m_Closable, m_Downloading, m_FromURL;
 
 		Platform::String^ FormatProgress();
 		void DoDownload(Platform::String^ url);

+ 2 - 2
winrt/SDLPal.Common/MainPage.xaml.cpp

@@ -200,7 +200,7 @@ void SDLPal::MainPage::CheckResourceFolder()
 		msgbox->Commands->Append(ref new UICommand(m_resLdr->GetString("MBButtonYes"), nullptr, 1));
 		msgbox->Commands->Append(ref new UICommand(m_resLdr->GetString("MBButtonNo"), nullptr, nullptr));
 		msgbox->DefaultCommandIndex = 0;
-		msgbox->CancelCommandIndex = 1;
+		msgbox->CancelCommandIndex = 0;
 		concurrency::create_task(msgbox->ShowAsync()).then([this](IUICommand^ command)->IAsyncOperation<IUICommand^>^ {
 			if (command->Id == nullptr)
 			{
@@ -211,7 +211,7 @@ void SDLPal::MainPage::CheckResourceFolder()
 			msgbox->Commands->Append(ref new UICommand(m_resLdr->GetString("MBButtonFromURL"), nullptr, 1));
 			msgbox->Commands->Append(ref new UICommand(m_resLdr->GetString("MBButtonFromBaiyou"), nullptr, -1));
 			msgbox->DefaultCommandIndex = 0;
-			msgbox->CancelCommandIndex = 1;
+			msgbox->CancelCommandIndex = 0;
 			return msgbox->ShowAsync();
 		}).then([this](IUICommand^ command)->IAsyncOperation<IUICommand^>^ {
 			if (command && command->Id && (int)command->Id == -1)

+ 1 - 1
winrt/SDLPal.Common/Strings/en/Resources.resw

@@ -360,7 +360,7 @@ Please choose the correct folder or download game resource from the offical webs
     <value>missing necessary game resource in folder</value>
   </data>
   <data name="URL.Header" xml:space="preserve">
-    <value>URL of the game resource's Zip archive</value>
+    <value>URL of game resource's Zip archive</value>
   </data>
   <data name="MBFolderManually" xml:space="preserve">
     <value>Please put game resource files into the folder before you select it.</value>