Beispiel #1
0
 // Helper function for getting a list of all EXEs and DLLs in the current application folder
 public static List <string> GetAssemblyFiles()
 {
     string[] exts = new string[2] {
         "*.exe", "*.dll"
     };
     return(ApplicationUtility.GetAssemblyFiles(ApplicationUtility._applicationBinFolder, exts, SearchOption.AllDirectories));
 }
        // Helper function to read the response from a Url and return a version state machine
        internal static async Task <VersionState> GetVersionFromSource(string pageSource)
        {
            // Create an instance of an HtmlAgilityPack Html document that we can load the Url response into
            HtmlDocument updateDoc = new HtmlDocument();

            // Create a default state machine of there being no new update
            VersionState state = new VersionState()
            {
                IsNewVersion = false, Url = String.Empty, Version = string.Empty
            };

            //Load the page source into the HtmlAgilityPack document so that we can parse the DOM effectively
            updateDoc.LoadHtml(pageSource);

            // Find any 'H3' elements in the document
            var pageH3s = updateDoc.DocumentNode.Descendants("h3");

            if (pageH3s != null)
            {
                // The first one that has a 'Zip' file as its source, is our upgrade file
                var firstZipLink = pageH3s.Select(h3 => h3.Descendants("a").FirstOrDefault(a => a.Attributes["href"] != null && a.Attributes["href"].Value != null && a.Attributes["href"].Value.ToLower().Contains(".zip"))).FirstOrDefault(item => item != null);

                if (firstZipLink != null)
                {
                    var linkVersion = firstZipLink.Attributes["data-version"];

                    //List<string> linkText = firstZipLink.InnerText.Split(' ').ToList();
                    if (linkVersion?.Value != null)
                    {
                        // Use the link text to get the version number
                        string webVersionInfo = linkVersion.Value;

                        // Get the current version number (note the process DOESN'T take into account revisions...)
                        string appVersionInfo = ApplicationUtility.BuildVersion();

                        // Create an appropriate state machine for this versions
                        ApplicationUtility.VersionState currentState = ApplicationUtility.CompareVersions(appVersionInfo, webVersionInfo);

                        // Alter the state machine based on whether the remote version is newer
                        if (currentState == ApplicationUtility.VersionState.WebIsNewer)
                        {
                            state.IsNewVersion = true;
                            state.Version      = webVersionInfo;
                            state.Url          = firstZipLink.Attributes["href"].Value;
                        }
                    }
                }
            }

            // Clear up and close the HtmlAgilityPack document
            updateDoc = null;

            return(state);
        }
Beispiel #3
0
        // Helper function for getting a list of filename and version numbers of all assembly files (EXEs and DLLs) in the
        // current application folder
        public static List <string> GetApplicationComponentVersions()
        {
            List <string> stringList = new List <string>();

            string[] exts = new string[2] {
                "*.exe", "*.dll"
            };
            foreach (string assemblyFile in ApplicationUtility.GetAssemblyFiles(ApplicationUtility._applicationBinFolder, exts, SearchOption.AllDirectories))
            {
                FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(assemblyFile);
                if (!string.IsNullOrEmpty(versionInfo.Comments))
                {
                    string str = string.Format("{0} ({1}) - version: {2}", (object)versionInfo.Comments, (object)versionInfo.InternalName, (object)versionInfo.FileVersion);
                    stringList.Add(str);
                }
            }
            return(stringList);
        }
Beispiel #4
0
        // Helper function to determine if the current EXE has the focus
        public static bool ApplicationIsActivated()
        {
            bool isApplicationActive = false;

            // Find the window handle of the window the user currently has activated
            IntPtr foregroundWindow = ApplicationUtility.GetForegroundWindow();

            // If the user has a window active
            if (foregroundWindow != IntPtr.Zero)
            {
                // Get the process Id of the application currently referencing this DLL
                int id = Process.GetCurrentProcess().Id;
                int processId;

                // Get the process Id of the application that the user is currently interacting with
                ApplicationUtility.GetWindowThreadProcessId(foregroundWindow, out processId);

                // If Windows says the user is using our application, then it's active
                isApplicationActive = processId == id;
            }

            return(isApplicationActive);
        }
Beispiel #5
0
 // Helper function to get the current version number (used by the version checker system)
 // TODO: determine if this is un-necessarily duplicated
 public static string BuildVersion()
 {
     return(ApplicationUtility.GetApplicationVersionNumber());
 }