private void Export() { List <ModNode> modsToExport = GetModsToExport(); if (modsToExport.Count <= 0) { MessageBox.Show(this, Messages.MSG_NO_MODS_TO_EXPORT, Messages.MSG_TITLE_ATTENTION); Messenger.AddInfo(Messages.MSG_NO_MODS_TO_EXPORT); } else { SaveFileDialog dlg = new SaveFileDialog(); dlg.InitialDirectory = OptionsController.DownloadPath; dlg.FileName = RemoveInvalidCharsFromPath(string.Format(MODPACK_FILENAME_TEMPLATE, DateTime.Now.ToShortDateString())); if (dlg.ShowDialog() == DialogResult.OK) { pbExport.Visible = true; AddMessage(string.Format(Messages.MSG_EXPORT_TO_0, dlg.FileName)); AsyncTask <bool> .DoWork(() => { ModPackHandler.MessageCallbackFunction = AddMessage; ModPackHandler.Export(modsToExport, dlg.FileName, cbIncludeMods.Checked); ModPackHandler.MessageCallbackFunction = null; return(true); }, (b, ex) => { pbExport.Visible = false; if (ex != null) { AddMessage(string.Format(Messages.MSG_ERROR_EXPORT_FAILED_0, ex.Message), true, ex); MessageBox.Show(this, string.Format(Messages.MSG_ERROR_EXPORT_FAILED_0, ex.Message), Messages.MSG_TITLE_ERROR); } else { AddMessage(Messages.MSG_EXPORT_DONE); Close(); } }); } else { AddMessage(Messages.MSG_EXPORT_ABORTED); } } }
private void Import() { AddMessage(Messages.MSG_IMPORT_STARTED); OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = OptionsController.DownloadPath; dlg.Filter = Constants.MODPACK_FILTER; if (dlg.ShowDialog() == DialogResult.OK) { pbImport.Visible = true; new AsyncTask <bool>(() => { if (cbClearModSelection.Checked) { AddMessage(Messages.MSG_CLEARING_MODSELECTION); InvokeIfRequired(() => ModSelectionController.RemoveAllMods()); } AddMessage(string.Format(Messages.MSG_IMPORTING_FROM_0, dlg.FileName)); ModPackHandler.MessageCallbackFunction = AddMessage; ModPackHandler.Import(dlg.FileName, OptionsController.DownloadPath, cbExtract.Checked, cbDownloadIfNeeded.Checked, rbCopyDestination.Checked, rbAddOnly.Checked); ModPackHandler.MessageCallbackFunction = null; return(true); }, (b, ex) => { pbImport.Visible = false; if (ex != null) { AddMessage(Messages.MSG_IMPORTING_FAILED, true, ex); MessageBox.Show(this, ex.Message, Messages.MSG_TITLE_ERROR); } else { AddMessage(Messages.MSG_IMPORTING_DONE); Close(); } }).Run(); } else { AddMessage(Messages.MSG_IMPORTING_ABORTED); } }