/// <summary> /// Packages a mod into an auto-install ZIP file /// </summary> /// <param name="info">The mod information to be edited</param> /// <param name="path">The path of the mod info file</param> public static void PackageMod(ModInfo info, string path) { #region Sanity checks if (info == null) { throw new ArgumentNullException(nameof(info)); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } #endregion var dialog = new ModPackageDialog { _modProjectFile = path, _modDirPath = Path.GetDirectoryName(path), saveFileDialog = { FileName = info.Name + FileExt } }; dialog.ShowDialog(); }
private void buttonOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textName.Text)) { errorProvider.SetError(textName, Resources.MissingModName); textName.Focus(); return; } if (_info == null) { if (string.IsNullOrEmpty(textLocation.Text)) { errorProvider.SetError(textLocation, Resources.MissingStorageLocation); textLocation.Focus(); return; } _location = textLocation.Text; // Check the directory is empty if (Directory.Exists(_location) && Directory.GetFiles(_location).Length > 0) { if (!Msg.YesNo(this, Resources.DirectoryNotEmpty, MsgSeverity.Warn, Resources.DirectoryNotEmptyContinue, Resources.DirectoryNotEmptyCancel)) { textLocation.Focus(); return; } } // Try to create directory for new mod try { Directory.CreateDirectory(_location); } #region Error handling catch (ArgumentException) { errorProvider.SetError(textLocation, Resources.InvalidDirectoryPath); textLocation.Focus(); return; } catch (NotSupportedException) { errorProvider.SetError(textLocation, Resources.InvalidDirectoryPath); textLocation.Focus(); return; } catch (IOException) { errorProvider.SetError(textLocation, Resources.DirectoryNotCreatable); textLocation.Focus(); return; } catch (UnauthorizedAccessException) { errorProvider.SetError(textLocation, Resources.DirectoryNotCreatable); textLocation.Focus(); return; } #endregion _info = new ModInfo(); } // Store mod information _info.Name = textName.Text; _info.Version = textVersion.Text; _info.Author = textAuthor.Text; _info.Website = textWebsite.Text; _info.Description = textDescription.Text; DialogResult = DialogResult.OK; Close(); }