Esempio n. 1
0
        /// <summary>
        /// </summary>
        public bool CleanUpOrphanBuilds()
        {
            bool Result = false;

            foreach (StorageLocation Location in Locations)
            {
                string BuildPath = Path.Combine(Location.Path, @"Builds");

                if (Directory.Exists(BuildPath))
                {
                    // Check if there are any folders in the storage directory that do not have a manifest associated with them.
                    foreach (string Dir in Directory.GetDirectories(BuildPath))
                    {
                        Guid ManifestId = Guid.Empty;

                        if (Guid.TryParse(Path.GetFileName(Dir), out ManifestId))
                        {
                            // This download is currently being worked on, don't try and clean it up.
                            if (DownloadManager.IsDownloadBlocked(ManifestId))
                            {
                                continue;
                            }

                            BuildManifest Manifest = ManifestRegistry.GetManifestById(ManifestId);
                            if (Manifest == null)
                            {
                                lock (PendingDirectoryCleanups)
                                {
                                    if (!PendingDirectoryCleanups.Contains(Dir))
                                    {
                                        Logger.Log(LogLevel.Info, LogCategory.Manifest, "Deleting directory in storage folder that appears to have no matching manifest (probably a previous failed delete): {0}", Dir);
                                        PendingDirectoryCleanups.Add(Dir);
                                        IOQueue.DeleteDir(Dir, bSuccess => { PendingDirectoryCleanups.Remove(Dir); });
                                        Result = true;
                                    }
                                }
                            }
                            else
                            {
                                // If we have a manifest but no download state add as local download
                                // with no available blocks so we can clean it up if needed for space.
                                if (DownloadManager.GetDownload(ManifestId) == null)
                                {
                                    Logger.Log(LogLevel.Info, LogCategory.Manifest, "Found build directory for manifest, but no download state, added as local download, might have been orphaned due to settings save failure?: {0}", Dir);
                                    DownloadManager.AddLocalDownload(Manifest, Dir, false);
                                    Result = true;
                                }
                            }
                        }
                    }
                }
            }

            return(Result);
        }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        public static void InstallAutoUpdate(bool SilentInstall)
        {
            ManifestDownloadState AutoUpdateDownload = null;

            if (InternalUpdateDownload != null)
            {
                AutoUpdateDownload = ManifestDownloadManager.GetDownload(InternalUpdateDownload.ActiveManifestId);
            }

            if (AutoUpdateDownload == null)
            {
                Logger.Log(LogLevel.Error, LogCategory.Main, "Failed to install update, no internal download available.");
                return;
            }

            string InstallerPath = Path.Combine(AutoUpdateDownload.LocalFolder, "installer.msi");

            if (!File.Exists(InstallerPath))
            {
                MessageBox.Show("Buildsync installer cannot be found in update download. Update is likely corrupt", "Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // Boot up the installer.
                try
                {
                    IOQueue.CloseAllStreamsInDirectory(AutoUpdateDownload.LocalFolder);

                    Process p = new Process();
                    p.StartInfo.FileName = "msiexec";
                    if (SilentInstall)
                    {
                        p.StartInfo.Arguments = "/i \"" + InstallerPath + "\" /passive /norestart REINSTALL=ALL REINSTALLMODE=A MSIRMSHUTDOWN=1 MSIDISABLERMRESTART=0 ADDLOCAL=All";
                    }
                    else
                    {
                        p.StartInfo.Arguments = "/i \"" + InstallerPath + "\"";
                    }
                    p.StartInfo.UseShellExecute  = false;
                    p.StartInfo.WorkingDirectory = AutoUpdateDownload.LocalFolder;
                    p.Start();

                    Environment.Exit(0);
                }
                catch (Exception Ex)
                {
                    Logger.Log(LogLevel.Error, LogCategory.Main, "Failed to install update '{0}' due to error: {1}", InstallerPath, Ex.Message);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Msg"></param>
        private void SolicitRemoteActionRecieved(NetMessage_SolicitRemoteAction Msg)
        {
            bool Accepted = false;

            // Don't accept if we are running any other actions.
            if (!IsRunningRemoteActions())
            {
                if (Msg.Type == RemoteActionType.Install)
                {
                    Guid ManifestId = Guid.Parse(Msg.Settings["ManifestId"]);

                    ManifestDownloadState State = DownloadManager.GetDownload(ManifestId);
                    if (State != null && State.State == ManifestDownloadProgressState.Complete)
                    {
                        try
                        {
                            // TODO: We don't support json files here. Should we just remove them? Nobody uses them.

                            string ConfigFilePath = Path.Combine(State.LocalFolder, "buildsync.cs");

                            BuildSettings Settings = new BuildSettings();
                            Settings.ScriptSource = File.ReadAllText(ConfigFilePath);

                            List <BuildLaunchMode> Modes;
                            Modes = Settings.Compile();

                            Accepted = (Modes.Count > 0);
                        }
                        catch (Exception Ex)
                        {
                            // We cannot compile or use this script :(
                        }
                    }
                }
            }

            if (Accepted)
            {
                NetMessage_SolicitAcceptRemoteAction Reply = new NetMessage_SolicitAcceptRemoteAction();
                Reply.ActionId = Msg.ActionId;
                Client.Connection.Send(Reply);
            }
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        public void RecieveReplicatedBuilds(NetMessage_GetFilteredBuildsResponse.BuildInfo[] Builds)
        {
            if (!AutoReplicate)
            {
                return;
            }

            Logger.Log(LogLevel.Info, LogCategory.Download, "Recieved {0} replicated builds from server.", Builds.Length);

            foreach (NetMessage_GetFilteredBuildsResponse.BuildInfo Build in Builds)
            {
                Logger.Log(LogLevel.Info, LogCategory.Download, "\tBuild:{0} Path:{1}", Build.Guid.ToString(), Build.VirtualPath);

                // Manifest is being manipulated elsewhere.
                if (ManifestDownloader.IsDownloadBlocked(Build.Guid))
                {
                    continue;
                }

                // Already downloaded/downloading.
                ManifestDownloadState State = ManifestDownloader.GetDownload(Build.Guid);
                if (State != null)
                {
                    continue;
                }

                // Create a new download.
                AddDownload(
                    "Automatic Replication",
                    Build.VirtualPath,
                    0,
                    BuildSelectionRule.Newest,
                    BuildSelectionFilter.None,
                    "",
                    "",
                    false,
                    false,
                    "",
                    "",
                    new List <Guid>(),
                    new List <Guid>(),
                    true
                    );
            }
        }