private void buttonUpdate_Click(object sender, EventArgs e) { UpdateVersionString(true); Enabled = false; try { foreach (Project p in Projects) { listBoxProjects.SelectedItem = p.DirectoryPath; Application.DoEvents(); ProjectPatcher.Patch(p, textBoxVersion.Text); } ini.Save(); Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { Enabled = true; } }
void AutoUpdate(Arguments arguments) { SystemConsole.WriteLine(Banner); SystemConsole.WriteLine(); List <Project> projects = LoadProjects(arguments); SystemConsole.WriteLine("Solution {0} with {1} projects loaded.", Solution, projects.Count); string fileName = Path.GetFullPath(Solution + ".ver"); FileSystem.TouchFile(fileName); Ini ini = new Ini(fileName); int major = ini.ReadInt32("Version", "Major", 0); int minor = ini.ReadInt32("Version", "Minor", 0); int patch = ini.ReadInt32("Version", "Patch", 0); string meta = ini.ReadSetting("Version", "Meta"); if (meta == null) { meta = ""; } bool metaAddConfig = ini.ReadBool("Version", "AddConfig", true); bool metaAddDateTime = ini.ReadBool("Version", "AddDateTime", true); int semVerType = ini.ReadInt32("Version", "Type", 0); if (arguments.IsOptionPresent("stable")) { meta = null; if (int.TryParse(arguments.Options["stable"].Value, out int stablePatch)) { patch = stablePatch; } if (arguments.IsOptionPresent("increment")) { patch++; } } else { if (arguments.IsOptionPresent("increment")) { patch++; } meta = new string(meta.Where(c => (c >= 'a' && c <= 'z') || (c == '+') || (c == '-')).ToArray()); if (metaAddConfig) { if (meta.Length > 0) { meta += (meta.LastIndexOf('+') > meta.LastIndexOf('-')) ? '+' : '-'; } meta += "$CONF$"; } if (metaAddDateTime) { meta += (semVerType == 1) ? '.' : ((meta.LastIndexOf('+') > meta.LastIndexOf('-')) ? '+' : '-'); meta += "$DATETIME$"; } } string semVer; if (string.IsNullOrWhiteSpace(meta)) { semVer = $"{major}.{minor}.{patch}"; } else { switch (semVerType) { //version 1 default: meta = meta.Split(".-+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Join("-"); semVer = $"{major}.{minor}.{patch}-{meta}"; break; //version 2 case 1: semVer = $"{major}.{minor}.{patch}-{meta}"; break; } } SystemConsole.WriteLine("Patching to version <cyan>{0}", semVer); foreach (Project project in projects) { SystemConsole.WriteLine("Patching project <cyan>{0}<default> with version <cyan>{1}", Path.GetFileName(project.FullPath), semVer); ProjectPatcher.Patch(project, semVer); } SystemConsole.WriteLine("{0} projects patched.", projects.Count); }