private async void ImportButtonClicked(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog(); Nullable <bool> result = openFileDlg.ShowDialog(); if (result == true) { string directory = Path.Combine(IMPORTED_VERSIONS_PATH, openFileDlg.SafeFileName); if (Directory.Exists(directory)) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("A version with the same name was already imported. Do you want to delete it ?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { Directory.Delete(directory, true); } else { return; } } var versionEntry = _versions.AddEntry(openFileDlg.SafeFileName, directory); await Task.Run(() => { versionEntry.StateChangeInfo = new VersionStateChangeInfo(VersionState.Extracting); ZipFile.ExtractToDirectory(openFileDlg.FileName, directory); versionEntry.StateChangeInfo = null; }); MessageBox.Show("Successfully imported appx: " + openFileDlg.FileName); } }
private async void ImportButtonClicked(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog(); openFileDlg.Filter = "UWP App Package (*.appx)|*.appx|All Files|*.*"; Nullable <bool> result = openFileDlg.ShowDialog(); if (result == true) { string directory = Path.Combine(IMPORTED_VERSIONS_PATH, openFileDlg.SafeFileName); if (Directory.Exists(directory)) { var found = false; foreach (var version in _versions) { if (version.IsImported && version.GameDirectory == directory) { if (version.IsStateChanging) { MessageBox.Show("A version with the same name was already imported, and is currently being modified. Please wait a few moments and try again.", "Error"); return; } MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("A version with the same name was already imported. Do you want to delete it ?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { await Remove(version); found = true; break; } else { return; } } } if (!found) { MessageBox.Show("The destination path for importing already exists and doesn't contain a Minecraft installation known to the launcher. To avoid loss of data, importing was aborted. Please remove the files manually.", "Error"); return; } } var versionEntry = _versions.AddEntry(openFileDlg.SafeFileName, directory); versionEntry.StateChangeInfo = new VersionStateChangeInfo(VersionState.Extracting); await Task.Run(() => { try { ZipFile.ExtractToDirectory(openFileDlg.FileName, directory); } catch (InvalidDataException ex) { Debug.WriteLine("Failed extracting appx " + openFileDlg.FileName + ": " + ex.ToString()); MessageBox.Show("Failed to import appx " + openFileDlg.SafeFileName + ". It may be corrupted or not an appx file.\n\nExtraction error: " + ex.Message, "Import failure"); return; } finally { versionEntry.StateChangeInfo = null; } }); } }
private async void ImportButtonClicked(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog(); openFileDlg.Filter = "UWP App Package (*.appx)|*.appx|All Files|*.*"; Nullable <bool> result = openFileDlg.ShowDialog(); if (result == true) { string directory = Path.Combine(IMPORTED_VERSIONS_PATH, openFileDlg.SafeFileName); if (Directory.Exists(directory)) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("A version with the same name was already imported. Do you want to delete it ?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { Directory.Delete(directory, true); } else { return; } } var versionEntry = _versions.AddEntry(openFileDlg.SafeFileName, directory); await Task.Run(() => { versionEntry.StateChangeInfo = new VersionStateChangeInfo(VersionState.Extracting); try { ZipFile.ExtractToDirectory(openFileDlg.FileName, directory); } catch (InvalidDataException ex) { Debug.WriteLine("Failed extracting appx " + openFileDlg.FileName + ": " + ex.ToString()); MessageBox.Show("Failed to import appx " + openFileDlg.SafeFileName + ". It may be corrupted or not an appx file.\n\nExtraction error: " + ex.Message, "Import failure"); return; } finally { versionEntry.StateChangeInfo = null; } MessageBox.Show("Successfully imported appx: " + openFileDlg.FileName); }); } }