Пример #1
0
        /// <summary>
        /// INIT LICENSING FOR FORM - CALL THIS
        /// Inserts about tab on menu strip
        /// </summary>
        /// <param name="baseform">The baseform.</param>
        /// <param name="existingMenuStrip">The existing menu strip.</param>
        /// <param name="helpString"></param>
        /// <param name="otherText"></param>
        public static void LicensingForm(Form baseform, MenuStrip existingMenuStrip, string helpString, string otherText)
        {
            var a = AssemblyExtras.GetEntryAssemblyInfo();

            _sd = new SolutionDetails(
                GitHubLicensing.GetGitHubReleaseDetails,
                helpString,
                a.AppName, a.RepoName, a.CurrentVersion,
                otherText);

            baseform.Text = _sd.AppName + " Version:" + _sd.Ld.CurrentVersion;

            var          existed = false;
            const string help    = "&Help";

            var helpToolStripItem = GetItem(existingMenuStrip);

            if (helpToolStripItem != null)
            {
                existed = true;
            }
            else
            //if it doesnt, create
            {
                existingMenuStrip.Items.Add(new ToolStripMenuItem(help));
                //should always be set now
                helpToolStripItem = GetItem(existingMenuStrip);
            }

            //add the help window
            if (!string.IsNullOrEmpty(_sd.HelpText))
            {
                AddHelpOption(helpToolStripItem);
            }

            //check for updates button
            var updateitem = new ToolStripMenuItem("&Check For Updates");

            updateitem.Click += async(a1, b1) => { await UpdateEvent(a1, b1); };
            helpToolStripItem.DropDownItems.Add(updateitem);

            //about item
            var aboutitem = new ToolStripMenuItem("&About");

            aboutitem.Click += Aboutbox;
            helpToolStripItem.DropDownItems.Add(aboutitem);

            //add all the items to the menu if help didnt exist
            if (existed == false)
            {
                existingMenuStrip.Items.Add(helpToolStripItem);
            }
        }
Пример #2
0
        /// <summary>
        /// update process via console. if true, terminate console app in 1 second so update process can overwrite exe
        /// </summary>
        /// <returns></returns>
        public static async Task <bool> IsUpdateConsoleRequired(string helpString, string otherText)
        {
            var a = AssemblyExtras.GetEntryAssemblyInfo();

            _sd = new SolutionDetails(
                GitHubLicensing.GetGitHubReleaseDetails,
                helpString,
                a.AppName, a.RepoName, a.CurrentVersion,
                otherText);

            Console.WriteLine("--------------\r\nUPDATE PROCESS\r\n--------------");
            Console.WriteLine("This app will now connect to the internet to find  the newest version.\nDo you wish to continue? y/[n]");

            var ok = Console.ReadKey().Key.ToString();

            if (ok.ToLower() != "y")
            {
                return(false);
            }

            var det = await GetUpdateDetails();

            Console.WriteLine("\r\n>>" + det.ResponseMessage);

            if (det.Response != LicensingDetails.LicenseResponse.NewVersion)
            {
                return(false);
            }

            Console.WriteLine(
                det.OnlineVersion +
                "\n\nDo you wish to update to this version? y/[n] \n(Be aware that this program will restart; please save your data beforehand)");

            ok = Console.ReadKey().Key.ToString();
            if (ok.ToLower() != "y")
            {
                return(false);
            }

            UpdateApplication(det);
            return(true);
        }
Пример #3
0
        public static async Task Run(string[] args)
        {
            v = AssemblyExtras.GetCallingAssemblyInfo();
            var n = v.GetAppString();

            Console.Title = n;

            hWnd = FindWindow(null, n); //put your console window caption here
            ShowWindow(hWnd, (int)Controller.Operation.Hide);

            if (args.Length < 2 || args.Length > 4 || (args.Length == 1 && args[0].Equals("/?")))
            {
                printInstructions(true);
                await Licensing.UpdateConsole(HelpString, OtherText);

                KeyboardAndClose();
            }
            else
            {
                int    num  = 0;
                String path = "";
                var    op   = Operation.None;

                bool quote = false;
                foreach (var s in args)
                {
                    if (num == 0)
                    {
                        path = s;
                        var count = path.Count(ss => ss == '\"');
                        if (count == 1)
                        {
                            quote = true;
                        }
                    }
                    else
                    {
                        if (quote)
                        {
                            path += s;
                            if (path.Contains("\""))
                            {
                                quote = false;
                            }
                            continue;
                        }

                        var sl = s.ToLower();

                        switch (sl)
                        {
                        case "/min":
                            op = Operation.Min;
                            break;

                        case "/max":
                            op = Operation.Max;
                            break;

                        case "/normal":
                            op = Operation.Normal;
                            break;

                        case "/close":
                            op = Operation.Close;
                            break;
                        }
                    }

                    num++;
                }

                if (path.Length == 0)
                {
                    printErrorMessage("No Path Supplied");
                }
                if (op == Operation.None)
                {
                    printErrorMessage("Provide either min or max flag");
                }
                //get file to run
                //String sss = "start " + '"' + path + '"';
                String    sss             = " " + path;
                var       proc            = ExecuteCommandSync(sss);
                bool      performed       = false;
                const int maxtimeouts     = 10000;
                int       timeout         = 0;
                const int timeoutinterval = 1000;

                //Thread.Sleep(4000);

                while (performed == false)
                {
                    if (op == Operation.Close)
                    {
                        CloseWindow(proc.MainWindowHandle);
                        performed = true;
                        continue;
                    }
                    //min
                    var a = ShowWindow(proc.MainWindowHandle, (int)Operation.Min);
                    // Console.WriteLine("a="+a.ToString());
                    //max
                    var b = ShowWindow(proc.MainWindowHandle, (int)Operation.Max);
                    //Console.WriteLine("b=" + b.ToString());
                    //then perform user sizing
                    var c = ShowWindow(proc.MainWindowHandle, (int)op);
                    //Console.WriteLine("c=" + c.ToString());

                    if (c)
                    {
                        performed = true;
                    }
                    Thread.Sleep(timeoutinterval);
                    timeout += timeoutinterval;
                    if (timeout >= maxtimeouts)
                    {
                        return;
                    }
                }
            }
        }
Пример #4
0
        public static async Task Run(string[] args)
        {
            v = AssemblyExtras.GetEntryAssemblyInfo();
            var n = v.GetAppString();

            Console.Title = n;

            bool error = false;

            //parse args
            var packagename = "";
            var filetype    = "";
            var version     = "";
            var startpath   = "";

            try
            {
                for (int ai = 0; ai < args.Length; ai += 2)
                {
                    var index = args[ai];
                    var value = args[ai + 1];

                    if (index == "-n")
                    {
                        packagename = value;
                    }
                    else if (index == "-t")
                    {
                        filetype = "*." + value;
                    }
                    else if (index == "-v")
                    {
                        version = value;
                    }
                    else if (index == "-p")
                    {
                        startpath = value;
                    }
                }
            }
            catch (Exception e)
            {
                error = true;
            }

            if (string.IsNullOrEmpty(version))
            {
                version = null;
            }

            if (string.IsNullOrEmpty(filetype))
            {
                filetype = "*.csproj";
            }
            else
            {
                if (filetype.StartsWith("*.") == false)
                {
                    filetype = "*." + filetype;
                }
            }

            if (string.IsNullOrEmpty(packagename))
            {
                error = true;
            }

            if (string.IsNullOrEmpty(startpath))
            {
                startpath = null;
            }

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            string aversion = fvi.FileVersion;

            if (args.Length == 0 || error)
            {
                Console.WriteLine("\r\nNugetPackageUpdater V" + aversion + "\n");
                Console.WriteLine("Args: NugetPackageUpdater.exe");
                Console.WriteLine("-n PackageName (eg Antlr)");
                Console.WriteLine("[-t FileType (default: csproj)]");
                Console.WriteLine("[-v Version (default: newest from nuget)]");
                Console.WriteLine("[-p Start Path (default: current directory)]");
                if (await Licensing.IsUpdateConsoleRequired(HelpString, OtherText) == false)
                {
                    KeyboardAndClose();
                }
            }

            Console.WriteLine("\r\nNugetPackageUpdater V" + aversion + "\n");

            try
            {
                NugetRepos = NugetHelpers.GetLocalNugetRepos();
                ProjectFileChanges(filetype, packagename, version, startpath);
                PackagesChanges(packagename, version, startpath);
            }
            catch (Exception ex)
            {
                l.Error(ex, "Error occured:" + ex);
            }
        }
Пример #5
0
 public void InitLicensing()
 {
     Licensing.CreateLicense(this, menuStrip1,
                             new Licensing.SolutionDetails(GitHubLicensing.GetGitHubReleaseDetails, HelpString, AppTitle, AppRepo,
                                                           AssemblyExtras.GetAssemblyFileVersionInfo(), OtherText));
 }