/////////////////////////////////////////// static SystemSettings() { #if ANDROID platform = Platform.Android; #elif IOS platform = Platform.iOS; #else if (Environment.OSVersion.Platform == PlatformID.Unix) { platform = Platform.MacOS; //try //{ // if( AndroidAppNativeWrapper.IsAndroid() ) // platform = Platforms.Android; //} //catch { } } else if (UWPHelper.IsRunningAsUwp()) { platform = Platform.UWP; } else { platform = Platform.Windows; } #endif netRuntime = Type.GetType("Mono.Runtime", false) != null ? NetRuntimeType.Mono : NetRuntimeType.NetFramework; }
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); }
static void Main(string[] args) { MainViewModel.Current.Debug = args.Where(x => x.Trim().ToLower() == "-debug").Count() == 1; if (Debugger.IsAttached) { MainViewModel.Current.WorkDir = System.IO.Directory.GetCurrentDirectory(); } else { MainViewModel.Current.WorkDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); }; // - - - - - - commandLine = new CommandLineArguments(args); if (!MainViewModel.Current.Silent || MainViewModel.Current.ShowHelp || MainViewModel.Current.Debug) { Console.WriteLine(""); Console.WriteLine($"UpdateVersionInfo - V{MainViewModel.Current.UpdateVersionInfoVersion}"); Console.WriteLine(""); } ; if (MainViewModel.Current.Debug) { string cmd = $"{MainViewModel.Current.WorkDir} "; foreach (var c in args) { cmd += $"[{c}] "; } ; Console.WriteLine(cmd); Console.WriteLine(""); } ; if (ValidateCommandLine(commandLine)) { if (MainViewModel.Current.Info) { string formatStr = (MainViewModel.Current.Verbose ? "{0,6} {1,-10} - {2}" : "{0,6} {1,-10}"); foreach (var f in MainViewModel.Current.Files) { if (System.IO.File.Exists(f.Target)) { if (MainViewModel.Current.Debug) { Console.WriteLine($"File (2) #{MainViewModel.Current.Files.Count} [{f.Target}]"); } switch (f.Name) { case "vi": _VI_Helper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "", _VI_Helper.LastMessage, f.Target); } ; break; case "UWP": UWPHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "UWP", UWPHelper.LastMessage, f.Target); } ; break; case "Droid": DroidHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Droid", DroidHelper.LastMessage, f.Target); } ; break; case "WPF": break; case "iOS": iOSHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "iOS", iOSHelper.LastMessage, f.Target); } ; break; case "MacOS": break; case "Nuget": NugetHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Nuget", NugetHelper.LastMessage, f.Target); } ; break; case "Setup": DeployProjectHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Setup", DeployProjectHelper.LastMessage, f.Target); } ; break; } ; } ; } ; } else { string formatStr = (MainViewModel.Current.Verbose ? "{0,6} {1,-24} - {2}" : "{0,6} {1,-24}"); try { Version version = new Version( MainViewModel.Current.Major, MainViewModel.Current.Minor, MainViewModel.Current.Build.Value, MainViewModel.Current.Revision.HasValue ? MainViewModel.Current.Revision.Value : 0); foreach (var f in MainViewModel.Current.Files) { if (System.IO.File.Exists(f.Target)) { if (MainViewModel.Current.Debug) { Console.WriteLine($"File (1) #{MainViewModel.Current.Files.Count} [{f.Target}]"); } switch (f.Name) { case "vi": version = _VI_Helper.Update(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "", _VI_Helper.LastMessage, f.Target); } ; break; case "UWP": UWPHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "UWP", UWPHelper.LastMessage, f.Target); } ; break; case "Droid": DroidHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Droid", DroidHelper.LastMessage, f.Target); } ; break; case "WPF": break; case "iOS": iOSHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "iOS", iOSHelper.LastMessage, f.Target); } ; break; case "MacOS": break; case "Nuget": NugetHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Nuget", NugetHelper.LastMessage, f.Target); } ; break; case "Setup": DeployProjectHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Setup", DeployProjectHelper.LastMessage, f.Target); } ; break; } ; } ; } ; } catch (Exception e) { WriteHelp(commandLine, "An unexpected error was encountered:" + e.Message); } }; } ; if (Debugger.IsAttached) { Console.Read(); } ; }
static void Main(string[] args) { commandLine = new CommandLineArguments(args); if (!MainViewModel.Current.Silent) { Console.WriteLine(""); Console.WriteLine($"UpdateVersionInfo - V{MainViewModel.Current.UpdateVersionInfoVersion}"); Console.WriteLine(""); } ; if (ValidateCommandLine(commandLine)) { if (MainViewModel.Current.Info) { string formatStr = (MainViewModel.Current.Verbose ? "{0,6} {1,-10} - {2}" : "{0,6} {1,-10}"); foreach (var f in MainViewModel.Current.Files) { if (System.IO.File.Exists(f.Target)) { switch (f.Name) { case "vi": _VI_Helper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "", _VI_Helper.LastMessage, f.Target); } ; break; case "UWP": UWPHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "UWP", UWPHelper.LastMessage, f.Target); } ; break; case "Droid": DroidHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Droid", DroidHelper.LastMessage, f.Target); } ; break; case "WPF": break; case "iOS": iOSHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "iOS", iOSHelper.LastMessage, f.Target); } ; break; case "MacOS": break; case "Nuget": NugetHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Nuget", NugetHelper.LastMessage, f.Target); } ; break; case "Setup": DeployProjectHelper.GetVersion(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Setup", DeployProjectHelper.LastMessage, f.Target); } ; break; } ; } ; } ; } else { string formatStr = (MainViewModel.Current.Verbose ? "{0,6} {1,-24} - {2}" : "{0,6} {1,-24}"); try { Version version = new Version( MainViewModel.Current.Major, MainViewModel.Current.Minor, MainViewModel.Current.Build.Value, MainViewModel.Current.Revision.HasValue ? MainViewModel.Current.Revision.Value : 0); foreach (var f in MainViewModel.Current.Files) { if (System.IO.File.Exists(f.Target)) { switch (f.Name) { case "vi": version = _VI_Helper.Update(f.Target); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "", _VI_Helper.LastMessage, f.Target); } ; break; case "UWP": UWPHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "UWP", UWPHelper.LastMessage, f.Target); } ; break; case "Droid": DroidHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Droid", DroidHelper.LastMessage, f.Target); } ; break; case "WPF": break; case "iOS": iOSHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "iOS", iOSHelper.LastMessage, f.Target); } ; break; case "MacOS": break; case "Nuget": NugetHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Nuget", NugetHelper.LastMessage, f.Target); } ; break; case "Setup": DeployProjectHelper.Update(f.Target, version); if (!MainViewModel.Current.Silent) { Console.WriteLine(formatStr, "Setup", DeployProjectHelper.LastMessage, f.Target); } ; break; } ; } ; } ; } catch (Exception e) { WriteHelp(commandLine, "An unexpected error was encountered:" + e.Message); } }; } ; if (Debugger.IsAttached) { Console.Read(); } ; }