private static bool ValidateCommandLine(CommandLineArguments commandLine) { if (MainViewModel.Current.ShowHelp) { WriteHelp(commandLine); return(true); } var errors = new System.Text.StringBuilder(); if (MainViewModel.Current.Major < 0) { errors.AppendLine("You must supply a positive major version number."); } if (MainViewModel.Current.Minor < 0) { errors.AppendLine("You must supply a positive minor version number."); } if (!MainViewModel.Current.Build.HasValue && !MainViewModel.Current.Info) { errors.AppendLine("You must supply a numeric build number."); } if (!MainViewModel.Current.ScanFiles) { if (!String.IsNullOrEmpty(MainViewModel.Current.VersionCsPath) && !UWPHelper.IsValid(MainViewModel.Current.VersionCsPath)) { errors.AppendLine("You must supply valid path to a writable C# file containing assembly version information."); } ; if (!String.IsNullOrEmpty(MainViewModel.Current.AndroidManifestPath) && !DroidHelper.IsValid(MainViewModel.Current.AndroidManifestPath)) { errors.AppendLine("You must supply valid path to a writable android manifest file."); } ; if (!String.IsNullOrEmpty(MainViewModel.Current.TouchPListPath) && !iOSHelper.IsValid(MainViewModel.Current.TouchPListPath)) { errors.AppendLine("You must supply valid path to a writable plist file containing version information."); } ; } ; if (errors.Length > 0) { WriteHelp(commandLine, "Invalid command line:\n" + errors.ToString()); } return(errors.Length == 0); }
public CommandLineArguments(IEnumerable <String> args) { MainViewModel.Current.Major = 1; MainViewModel.Current.Minor = 0; _options = Initialize(); // - - - - - - List <string> _args = args.ToList(); List <string> _args2 = args.ToList(); foreach (var st in _args) { if (st.ToLower().StartsWith("-v") && st.Contains(".")) { var a = st.Split(new char[] { '=', '.' }); if (a.Length == 5) { _args2[_args2.IndexOf(st)] = "-v=" + a[1]; _args2.Add("-m=" + a[2]); _args2.Add("-b=" + a[3]); _args2.Add("-r=" + a[4]); } ; } ; if (st.ToLower().StartsWith("-v") && st.ToLower().Contains("auto")) { MainViewModel.Current.AutoVersion = true; _args2[_args2.IndexOf(st)] = "-v=1"; _args2.Add("-m=0"); _args2.Add("-b=0"); _args2.Add("-r=0"); } ; if (st.ToLower().StartsWith("-p") && (st.ToLower().Contains("scan") || st.ToLower().Contains("auto"))) { MainViewModel.Current.ScanFiles = true; MainViewModel.Current.Files.Clear(); if (MainViewModel.Current.Debug) { Console.WriteLine($"WorkDir {MainViewModel.Current.WorkDir}"); } var allFiles = System.IO.Directory.EnumerateFiles(MainViewModel.Current.WorkDir, "*.*", System.IO.SearchOption.AllDirectories); if (MainViewModel.Current.Debug) { Console.WriteLine($"allFiles {MainViewModel.Current.WorkDir} {allFiles.Count()}"); } var files = allFiles.Where( x => x.ToLower().Contains(@"\properties\") || x.ToLower().EndsWith(@"\info.plist") || x.ToLower().EndsWith(@"\package.appxmanifest") || x.ToLower().EndsWith(@"\versioninfo.cs") || x.ToLower().EndsWith(@".vdproj") || x.ToLower().EndsWith(@".csproj") || x.ToLower().EndsWith(@".nuspec") ).ToList(); if (MainViewModel.Current.Debug) { Console.WriteLine($"files (3) {files.Count()}"); } foreach (var f in files) { if (f.ToLower().EndsWith(@"\versioninfo.cs")) { MainViewModel.Current.Files.Insert(0, new FileAndType { Name = "vi", Target = f }); } ; if (UWPHelper.IsValid(f)) { if (f.ToLower().EndsWith(@"\assemblyinfo.cs")) { if (System.IO.Directory.EnumerateFiles(System.IO.Path.GetDirectoryName(f), "Default.rd.xml", System.IO.SearchOption.TopDirectoryOnly).Count() == 1) { MainViewModel.Current.Files.Add(new FileAndType { Name = "UWP", Target = f }); try { _args2[_args2.IndexOf(st)] = $"-p={f}"; } catch { }; } ; } ; if (f.ToLower().EndsWith(@"\package.appxmanifest")) { MainViewModel.Current.Files.Add(new FileAndType { Name = "UWP", Target = f }); } ; } ; if (System.IO.Directory.EnumerateFiles(System.IO.Path.GetDirectoryName(f), "AndroidManifest.xml", System.IO.SearchOption.TopDirectoryOnly).Count() == 1) { if (DroidHelper.IsValid(f)) { MainViewModel.Current.Files.Add(new FileAndType { Name = "Droid", Target = f }); } ; } ; //if (WPFHelper.IsValid(f)) //{ //if (System.IO.Directory.EnumerateFiles(System.IO.Path.GetDirectoryName(f), "Settings.settings", System.IO.SearchOption.TopDirectoryOnly).Count() == 1) //{ // MainViewModel.Current.WPFAssemblyInfoPath = f; //MainViewModel.Current.Files.Add(new FileAndType { Name = "WPF", Value = f }); //}; //}; if (iOSHelper.IsValid(f)) { if (System.IO.File.ReadAllText(f).ToLower().Contains("minimumosversion")) { MainViewModel.Current.Files.Add(new FileAndType { Name = "iOS", Target = f }); //MainViewModel.Current.TouchPListPath = f; } ; } ; //if (MacHelper.IsValid(f)) //{ // if (System.IO.File.ReadAllText(f).ToLower().Contains("lsminimumsystemversion")) // { // MainViewModel.Current.MacPListPath = f; //MainViewModel.Current.Files.Add(new FileAndType { Name = "MacOS", Value = f }); // }; //}; if (NugetHelper.IsValid(f)) { //MainViewModel.Current.nuspecPath = f; MainViewModel.Current.Files.Add(new FileAndType { Name = "Nuget", Target = f }); } ; if (DeployProjectHelper.IsValid(f)) { MainViewModel.Current.Files.Add(new FileAndType { Name = "Setup", Target = f }); } ; } ; } ; } ; // - - - - - - _options.Parse(_args2); }