コード例 #1
0
ファイル: Service1.cs プロジェクト: brett-johnson/prototypes
            public bool GetFile(UpdateRegistry reg, string filename)
            {
                try
                {
                  string file_url = mAddress + filename;
                  string file_path = mStagingFolder + "\\" + filename;

                  LogMessage("downloading: " + file_path);

                  using (WebClient browser = new WebClient())
                  {
                browser.DownloadFile(file_url, file_path);
                LogMessage("download successful: " + file_path);
                  }
                  return true;
                }
                catch (System.Net.WebException e)
                {
                  LogException("Web: " + e.ToString());
                }
                catch (System.NotSupportedException e)
                {
                  LogException("Web: " + e.ToString());
                }
                catch (System.Exception e)
                {
                  LogException("Web: " + e.ToString());
                }

                return false;
            }
コード例 #2
0
ファイル: Service1.cs プロジェクト: brett-johnson/prototypes
        public static int[] GetNewVersion(UpdateRegistry reg, Downloader downloader)
        {
            try
              {
            string file_name = "agent_version.txt";
            if (!downloader.GetFile(reg, file_name))
            {
              LogMessage("ERROR: could not get: " + file_name);
              return new int[0];
            }

            string upgrade_version_file = downloader.mStagingFolder + "\\" + file_name;
            int[] upgrade_version = GetVersionInfo(reg, upgrade_version_file);
            if (upgrade_version.Length == 0)
            {
              LogMessage("ERROR: getting version info from: " + upgrade_version_file);
              return new int[0];
            }

            string installed_version_file = reg.mInstallFolder + file_name;
            int[] installed_version = GetVersionInfo(reg);

            // save the last time we checked for updates
            reg.SaveUpdateTime();

            if (upgrade_version[0] != installed_version[0] ||
              upgrade_version[1] != installed_version[1] ||
              upgrade_version[2] != installed_version[2])
            {
              // NOTE: installed version file is updated by the MSI
              return upgrade_version;
            }

            // NOTE: If we set the time here, we will continue to upgrade until we are current;
            // however, that could also get us into an endless loop, if we mess up the version
            // numbers.
            //reg.SaveUpdateTime();
              }
              catch (System.ArgumentNullException e)
              {
            LogException("version null argument: " + e);
              }
              catch (System.IO.PathTooLongException e)
              {
            LogException("version path: " + e);
              }
              catch (System.IO.DirectoryNotFoundException e)
              {
            LogException("version directory: " + e);
              }
              catch (System.IO.IOException e)
              {
            LogException("version I/O: " + e);
              }
              catch (System.UnauthorizedAccessException e)
              {
            LogException("version unauthorized: " + e);
              }
              catch (System.NotSupportedException e)
              {
            LogException("version not supported: " + e);
              }
              catch (System.Security.SecurityException e)
              {
            LogException("version security: " + e);
              }
              catch (System.FormatException e)
              {
            LogException("version format: " + e);
              }
              catch (System.OverflowException e)
              {
            LogException("version overflow: " + e);
              }
              catch (System.Exception e)
              {
            LogException("version general: " + e);
              }

              return new int[0];
        }
コード例 #3
0
ファイル: Service1.cs プロジェクト: brett-johnson/prototypes
        public static void SelfUpdate(UpdateRegistry reg, Downloader downloader, int[] newVersion)
        {
            try
              {
            LogMessage("INSTALLING Driveclient");
            string version_text = newVersion[0].ToString() + "." + newVersion[1].ToString("00") + "." + newVersion[2].ToString("000000");
            string base_name = "driveclient-setup-" + version_text + ".msi";
            string msi = downloader.mStagingFolder + "\\" + base_name;
            if (reg.mDebug)
            {
              LogMessage("MSI: " + msi);
            }

            downloader.GetFile(reg, msi);
            ProcessStartInfo proc = new ProcessStartInfo();
            proc.CreateNoWindow = true;
            proc.RedirectStandardError = true;
            proc.RedirectStandardInput = true;
            proc.RedirectStandardOutput = true;
            proc.UseShellExecute = false;
            proc.ErrorDialog = false;
            proc.WindowStyle = ProcessWindowStyle.Hidden;
            proc.FileName = "msiexec.exe";
            proc.Arguments = "/qn /i " + msi + " /L*v " + downloader.mStagingFolder + "\\" + base_name + ".log";
            if (reg.mDebug)
            {
              LogMessage("installing with: " + proc.Arguments);
            }

            Process child = new Process();
            child.StartInfo = proc;
            if (child.Start())
            {
              LogMessage("install started: " + proc.Arguments);
              //child.WaitForExit();
              //string result = InterpretErrorCode(child.ExitCode);
              //LogMessage("install started: " + proc.Arguments + " exit status: \"" + result + "\"");
            }
            else
            {
              LogMessage("install failed to start: " + proc.Arguments);
            }
              }
              catch (System.Exception e)
              {
            LogException("install general: " + e);
              }
        }
コード例 #4
0
ファイル: Service1.cs プロジェクト: brett-johnson/prototypes
        public static void OnPollForUpgrade(object source, ElapsedEventArgs e)
        {
            UpdateRegistry reg = new UpdateRegistry();
              if (!reg.mIsValid)
              {
            return;
              }

              DateTime start_time = DateTime.Now.Date.AddMinutes(reg.mStartTime.Minute).AddHours(reg.mStartTime.Hour);
              if (start_time < reg.mLastTime)
              {
            LogMessage("SKIPPING UPDATE: " + start_time + " is earlier than " + reg.mLastTime);
            return;
              }

              // TODO: DOWNLOAD VERSION FROM RELEASE SERVER AND SEE IF WE NEED TO UPDATE
              Downloader downloader = new Downloader();
              int[] new_version = GetNewVersion(reg, downloader);
              if (new_version.Length != 3)
              {
            return;
              }
              // TODO: DOWNLOAD DRIVECLIENT VERSION FROM RELEASE SERVER AND INSTALL IT
              //       - INITIAL PROTOTYPE WILL NOT DOWNLOAD ANY FILES
              //       - SECOND PROTOTYPE WILL ONLY DOWNLOAD VERSION FILE
              //       - THIRD PROTOTYPE WILL DOWNLOAD MSI
              SelfUpdate(reg, downloader, new_version);

              // TODO: TO SPOOF THIS PROCESS:
              //       - PUT DUMMY VERSION FILE IN %TMP%
              //       - COMPILE VERSION 1.1 MSI AND RENAME IT
              //       - COMPILE VERSION 1.2 MSI AND COPY IT TO %TMP%
              //       - INSTALL VERSION 1.1 MSI
              //       - VERSION 1.1 MSI SHOULD CHECK VERSION FILE IN %TMP%
              //       - VERSION 1.1 MSI SHOULD EXECUTE VERSION 1.2 MSI FROM %TMP%
        }
コード例 #5
0
ファイル: Service1.cs プロジェクト: brett-johnson/prototypes
        public static int[] GetVersionInfo(UpdateRegistry reg, string filename)
        {
            int[] version_info = new int[0];
              string[] line = System.IO.File.ReadAllLines(filename);
              if (line.Length < 1)
              {
            LogMessage("ERROR: version file length");
            return version_info;
              }

              string[] section = line[0].Split('.');
              if (section.Length != 3)
              {
            LogMessage("ERROR: " + line[0] + " is not in the right format");
            return version_info;
              }

              version_info = new int[3];
              version_info[0] = Convert.ToInt32(section[0]);
              version_info[1] = Convert.ToInt32(section[1]);
              version_info[2] = Convert.ToInt32(section[2]);

              if (reg.mDebug)
              {
            LogMessage("version info major: " + section[0] + " minor: " + section[1] + " build: " + section[2] + " file name: " + filename);
              }

              return version_info;
        }
コード例 #6
0
ファイル: Service1.cs プロジェクト: brett-johnson/prototypes
        public static int[] GetVersionInfo(UpdateRegistry reg)
        {
            int[] version_info = new int[3];
              version_info[0] = reg.mVersionMajor;
              version_info[1] = reg.mVersionMinor;
              version_info[2] = reg.mVersionBuild;

              if (reg.mDebug)
              {
            LogMessage("version info major: " + version_info[0] + " minor: " + version_info[1] + " build: " + version_info[2]);
              }

              return version_info;
        }
コード例 #7
0
        public static void PollForUpgrade()
        {
            UpdateRegistry reg = new UpdateRegistry();
              if (!reg.mIsValid)
              {
            return;
              }

              DateTime start_time = DateTime.Now.Date.AddMinutes(reg.mStartTime.Minute).AddHours(reg.mStartTime.Hour);
              if (start_time < reg.mLastTime)
              {
            LogMessage("SKIPPING UPDATE: " + start_time + " is earlier than " + reg.mLastTime);
            return;
              }

              Downloader downloader = new Downloader();
              int[] new_version = GetNewVersion(reg, downloader);
              if (new_version.Length != 3)
              {
            return;
              }
              SelfUpdate(reg, downloader, new_version);
        }