Exemple #1
0
        private bool TryToUpdateFiles()
        {
            Log.Append("TryToUpdateFiles() - enter");
            if (!File.Exists(downloadsSchemaPath))
            {
                Starter.SetUpdateExistingStatus(false);
                Log.Append("if ( !File.Exists( downloadsSchemaPath ) )");
                return(true);
            }

            bool possibilityToChangeFilesToNewVersion = !Starter.SolutionExecuting && SyncHelper.EnterMutex(Starter.RunSolutionMutex, TRY_TO_UPDATE_FILES_TIME_OUT);

            Log.Append("possibilityToChangeFilesToNewVersion = " + possibilityToChangeFilesToNewVersion.ToString());

            if (possibilityToChangeFilesToNewVersion)
            {
                bool filesUpdated = UpdateFiles();

                SyncHelper.ExitMutex(Starter.RunSolutionMutex);

                return(filesUpdated);
            }
            else
            {
                Starter.SetUpdateExistingStatus(true, GetDownloadedUpdateNumber());
                return(false);
            }
        }
Exemple #2
0
        private bool RegistrateSolutionExecuting()
        {
            SyncHelper.EnterMutex(RunSolutionMutex);

            solutionExecuting = true;

            if (!RegistrateInRegisrty())
            {
                SyncHelper.ExitMutex(RunSolutionMutex);
                Splash.SplashWindow.HideWindow();
                MessageBox.Show("Не удается получить доступ к реестру. Обратитесь к системному администратору для получения прав.\r\n\r\nВетвь: " + RegistryHelper.RegistryMainNodeName,
                                "Aramis.NET",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                errorStart = true;
                return(false);
            }

            SyncHelper.ExitMutex(RunSolutionMutex);

            return(true);
        }
Exemple #3
0
        private void UpdaterThread_DoWork()
        {
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "Solution updater";
            }

            while (!stopWork)
            {
                Log.Append("while ( !stopWork )");

                if (SyncHelper.EnterMutex(TryToUpdateAramisSolution, 1000))
                {
                    Log.Append("if SyncHelper.EnterMutex( TryToUpdateAramisSolution, 1000 )");

                    TryToPerformUpdating();
                    Log.Append("TryToPerformUpdating();");

                    SyncHelper.ExitMutex(TryToUpdateAramisSolution);
                    Log.Append("SyncHelper.ExitMutex( TryToUpdateAramisSolution );");
                }

                if (timeToCheckForStarterUpdate && updateDatabaseExists)
                {
                    Log.Append("if ( timeToCheckForStarterUpdate )");

                    TryToUpdateStarter();
                    Log.Append("after TryToUpdateStarter();");
                }

                Log.Append("before UpdaterThread_DoWork Sleep();");
                Sleep();
                Log.Append("after UpdaterThread_DoWork Sleep();");
            }

            Log.Append("UpdaterThread_DoWork() - exit");
        }
Exemple #4
0
        private void TryToUpdateStarter()
        {
            string queryText = "select top 1 LEN([Data]) fileSize, [Data] from [Starter] where [FileName] = @FileName and [HashCode] <> @Hash";

            SqlConnection conn = DatabaseHelper.GetUpdateConnection();

            try
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(queryText, conn))
                {
                    cmd.Parameters.AddWithValue("@FileName", Path.GetFileName(STARTER_PATH));
                    string fileHash = GetUpdateStarterHash();
                    cmd.Parameters.AddWithValue("@Hash", fileHash == "" ? STARTER_HASH : fileHash);

                    using (SqlDataReader dataReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        if (dataReader.Read())
                        {
                            if (!SyncHelper.EnterMutex(starterRuningMutex, 1000))
                            {
                                return;
                            }

                            #region Checking for update directory existing

                            if (!Directory.Exists(Path.GetDirectoryName(UPDATE_STARTER_PATH)))
                            {
                                try
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(UPDATE_STARTER_PATH));
                                }
                                catch (Exception exp)
                                {
                                    Trace.WriteLine("Can't create starter update directory: " + exp.Message);
                                }
                            }

                            #endregion

                            long fileSize    = Convert.ToInt64(dataReader["fileSize"]);
                            bool updateSaved = saveTemporaryFile(UPDATE_STARTER_PATH, fileSize, dataReader);

                            SyncHelper.ExitMutex(starterRuningMutex);

                            if (!updateSaved)
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Trace.WriteLine(exp.Message);
                return;
            }
            finally
            {
                if (conn != null)
                {
                    ((IDisposable)conn).Dispose();
                }
            }

            lastCheckingForStarterUpdateTime = DateTime.Now;
        }