浏览代码

WinRT (downloading): fix crash on back/stop & fix screen layout

Lou Yihua 7 年之前
父节点
当前提交
5cab5230f4

+ 15 - 9
winrt/SDLPal.Common/DownloadDialog.xaml

@@ -7,23 +7,29 @@
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     mc:Ignorable="d"
-    Title="正在下载……"
-    PrimaryButtonText="停止"
+    Title=" "
+    PrimaryButtonText=" "
     PrimaryButtonClick="OnPrimaryButtonClick"
     MinHeight="0" MinWidth="0"
     Closing="OnClosing" Opened="OnOpened" SizeChanged="OnSizeChanged">
 
-    <StackPanel Orientation="Vertical">
-        <WebView x:Name="wvDownloadPage" NavigationStarting="OnNavigateStart" DOMContentLoaded="OnDOMContentLoaded" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto" />
-        <Grid x:Name="gridURL" HorizontalAlignment="Stretch">
+    <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">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition />
                 <ColumnDefinition Width="Auto" />
             </Grid.ColumnDefinitions>
             <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" />
+            <Button x:Name="btnGoTo" Grid.Column="1" VerticalAlignment="Bottom" Content="=>" Click="OnClick" />
         </Grid>
-        <ProgressBar x:Name="pbDownload" HorizontalAlignment="Stretch" Height="12" Margin="0,8,0,4" />
-        <TextBlock x:Name="tbProgress" HorizontalAlignment="Right" Height="20" Margin="0,4,0,0" Text="0 / 0" />
-    </StackPanel>
+        <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>
 </ContentDialog>

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

@@ -49,15 +49,14 @@ 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_InitialPhase(true), 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)
 {
 	InitializeComponent();
 
-	this->IsSecondaryButtonEnabled = false;
 	this->MaxWidth = w;
 	this->MaxHeight = h;
-	pbDownload->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
-	tbProgress->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
+	this->PrimaryButtonText = m_resLdr->GetString("ButtonBack");
+	spProgress->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
 	if (from_url)
 	{
 		wvDownloadPage->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
@@ -89,14 +88,16 @@ 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;
-	pbDownload->Visibility = Windows::UI::Xaml::Visibility::Visible;
-	tbProgress->Visibility = Windows::UI::Xaml::Visibility::Visible;
-	this->MaxHeight -= wvDownloadPage->ActualHeight + gridURL->ActualHeight - 48;
+	spProgress->Visibility = Windows::UI::Xaml::Visibility::Visible;
+	this->MaxHeight = 128 + 48;
+	this->Title = m_resLdr->GetString("DialogTitle");
 	this->PrimaryButtonText = m_resLdr->GetString("ButtonStop");
-	this->Title = m_title;
 	this->UpdateLayout();
+	m_Downloading = true;
 
 	concurrency::create_task([this, url]() {
 		Exception^ ex = nullptr;
@@ -279,6 +280,7 @@ void SDLPal::DownloadDialog::DoDownload(Platform::String^ url)
 				}
 				(ref new MessageDialog(string, m_resLdr->GetString("MBDownloadTitle")))->ShowAsync();
 			}
+			m_Downloading = false;
 			m_Closable = true;
 			Hide();
 		}));
@@ -295,24 +297,21 @@ void SDLPal::DownloadDialog::OnPrimaryButtonClick(Windows::UI::Xaml::Controls::C
 
 void SDLPal::DownloadDialog::OnClosing(Windows::UI::Xaml::Controls::ContentDialog^ sender, Windows::UI::Xaml::Controls::ContentDialogClosingEventArgs^ args)
 {
-	args->Cancel = !m_Closable;
+	args->Cancel = !m_Closable || m_Downloading;
 }
 
 
 void SDLPal::DownloadDialog::OnOpened(Windows::UI::Xaml::Controls::ContentDialog^ sender, Windows::UI::Xaml::Controls::ContentDialogOpenedEventArgs^ args)
 {
-	m_title = this->Title;
 	if (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 - gridURL->ActualHeight;
+		wvDownloadPage->Height = m_height - 128;
 		UpdateLayout();
 		wvDownloadPage->Navigate(ref new Uri(_url));
 	}
-	else
-	{
-		this->Title = " ";
-	}
 }
 
 
@@ -360,8 +359,11 @@ 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 - gridURL->ActualHeight;
+		wvDownloadPage->Height = e->NewSize.Height - 128;
+		UpdateLayout();
 	}
 }
 

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

@@ -21,11 +21,10 @@ namespace SDLPal
 		Windows::ApplicationModel::Resources::ResourceLoader^ m_resLdr;
 		Windows::Storage::StorageFolder^ m_folder;
 		Windows::Storage::Streams::IRandomAccessStream^ m_stream;
-		Platform::Object^ m_title;
 		Platform::String^ m_msgfile;
 		double m_width, m_height;
 		uint64_t m_totalBytes;
-		bool m_Closable, m_InitialPhase;
+		bool m_Closable, m_Downloading;
 
 		Platform::String^ FormatProgress();
 		void DoDownload(Platform::String^ url);

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

@@ -162,10 +162,10 @@
   <data name="Debug.Content" xml:space="preserve">
     <value>debug</value>
   </data>
-  <data name="Downloading.PrimaryButtonText" xml:space="preserve">
+  <data name="ButtonBack" xml:space="preserve">
     <value>back</value>
   </data>
-  <data name="Downloading.Title" xml:space="preserve">
+  <data name="DialogTitle" xml:space="preserve">
     <value>downloading...</value>
   </data>
   <data name="EnableAVI.Header" xml:space="preserve">

+ 2 - 2
winrt/SDLPal.Common/Strings/zh-hans/Resources.resw

@@ -162,10 +162,10 @@
   <data name="Debug.Content" xml:space="preserve">
     <value>调试信息</value>
   </data>
-  <data name="Downloading.PrimaryButtonText" xml:space="preserve">
+  <data name="ButtonBack" xml:space="preserve">
     <value>返回</value>
   </data>
-  <data name="Downloading.Title" xml:space="preserve">
+  <data name="DialogTitle" xml:space="preserve">
     <value>正在下载……</value>
   </data>
   <data name="EnableAVI.Header" xml:space="preserve">

+ 2 - 2
winrt/SDLPal.Common/Strings/zh-hant/Resources.resw

@@ -162,10 +162,10 @@
   <data name="Debug.Content" xml:space="preserve">
     <value>調試信息</value>
   </data>
-  <data name="Downloading.PrimaryButtonText" xml:space="preserve">
+  <data name="ButtonBack" xml:space="preserve">
     <value>返回</value>
   </data>
-  <data name="Downloading.Title" xml:space="preserve">
+  <data name="DialogTitle" xml:space="preserve">
     <value>正在下載……</value>
   </data>
   <data name="EnableAVI.Header" xml:space="preserve">