public DetectProjectSettingsTask(UserSelectedProjectSettings SelectedProject, string InDataFolder, string InCacheFolder, TextWriter InLog)
 {
     this.SelectedProject = SelectedProject;
     DataFolder           = InDataFolder;
     CacheFolder          = InCacheFolder;
     Log = InLog;
 }
示例#2
0
        int TryOpenProject(UserSelectedProjectSettings Project, int ReplaceTabIdx, OpenProjectOptions Options = OpenProjectOptions.None)
        {
            Log.WriteLine("Detecting settings for {0}", Project);
            using (DetectProjectSettingsTask DetectProjectSettings = new DetectProjectSettingsTask(Project, DataFolder, CacheFolder, new PrefixedTextWriter("  ", Log)))
            {
                string ErrorMessage;

                ModalTaskResult Result;
                if ((Options & OpenProjectOptions.Quiet) != 0)
                {
                    Result = ModalTask.Execute(this, DetectProjectSettings, "Opening Project", "Opening project, please wait...", out ErrorMessage);
                }
                else
                {
                    Result = PerforceModalTask.Execute(this, Project.LocalPath, Project.ServerAndPort, Project.UserName, DetectProjectSettings, "Opening Project", "Opening project, please wait...", Log, out ErrorMessage);
                }

                if (Result != ModalTaskResult.Succeeded)
                {
                    CreateErrorPanel(ReplaceTabIdx, Project, ErrorMessage);
                    return(-1);
                }
                return(TryOpenProject(DetectProjectSettings, ReplaceTabIdx, Options));
            }
        }
        private List <UserSelectedProjectSettings> ReadProjectList(string SettingName, string LegacySettingName)
        {
            List <UserSelectedProjectSettings> Projects = new List <UserSelectedProjectSettings>();

            string[] ProjectStrings = ConfigFile.GetValues(SettingName, null);
            if (ProjectStrings != null)
            {
                foreach (string ProjectString in ProjectStrings)
                {
                    UserSelectedProjectSettings Project;
                    if (UserSelectedProjectSettings.TryParseConfigEntry(ProjectString, out Project))
                    {
                        Projects.Add(Project);
                    }
                }
            }
            else if (LegacySettingName != null)
            {
                string[] LegacyProjectStrings = ConfigFile.GetValues(LegacySettingName, null);
                if (LegacyProjectStrings != null)
                {
                    foreach (string LegacyProjectString in LegacyProjectStrings)
                    {
                        if (!String.IsNullOrWhiteSpace(LegacyProjectString))
                        {
                            Projects.Add(new UserSelectedProjectSettings(null, null, UserSelectedProjectType.Local, null, LegacyProjectString));
                        }
                    }
                }
            }

            return(Projects);
        }
示例#4
0
        public void RequestProjectChange(WorkspaceControl Workspace, UserSelectedProjectSettings Project)
        {
            int TabIdx = TabControl.FindTabIndex(Workspace);

            if (TabIdx != -1)
            {
                TryOpenProject(Project, TabIdx);
            }
        }
        private OpenProjectWindow(UserSelectedProjectSettings Project, UserSettings Settings, string DataFolder, string CacheFolder, PerforceConnection DefaultConnection, TextWriter Log)
        {
            InitializeComponent();

            this.Settings = Settings;
            this.DetectedProjectSettings = null;
            this.DataFolder        = DataFolder;
            this.CacheFolder       = CacheFolder;
            this.DefaultConnection = DefaultConnection;
            this.Log = Log;

            if (Project == null)
            {
                LocalFileRadioBtn.Checked = true;
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(Project.ServerAndPort))
                {
                    ServerAndPortOverride = Project.ServerAndPort;
                }
                if (!String.IsNullOrWhiteSpace(Project.UserName))
                {
                    UserNameOverride = Project.UserName;
                }

                if (Project.ClientPath != null && Project.ClientPath.StartsWith("//"))
                {
                    int SlashIdx = Project.ClientPath.IndexOf('/', 2);
                    if (SlashIdx != -1)
                    {
                        WorkspaceNameTextBox.Text = Project.ClientPath.Substring(2, SlashIdx - 2);
                        WorkspacePathTextBox.Text = Project.ClientPath.Substring(SlashIdx);
                    }
                }

                if (Project.LocalPath != null)
                {
                    LocalFileTextBox.Text = Project.LocalPath;
                }

                if (Project.Type == UserSelectedProjectType.Client)
                {
                    WorkspaceRadioBtn.Checked = true;
                }
                else
                {
                    LocalFileRadioBtn.Checked = true;
                }
            }

            UpdateEnabledControls();
            UpdateServerLabel();
            UpdateWorkspacePathBrowseButton();
            UpdateOkButton();
        }
 private UserSelectedProjectSettings UpgradeSelectedProjectSettings(UserSelectedProjectSettings Project)
 {
     if (Project.ServerAndPort == null || String.Compare(Project.ServerAndPort, DefaultConnection.ServerAndPort, StringComparison.OrdinalIgnoreCase) == 0)
     {
         if (Project.UserName == null || String.Compare(Project.UserName, DefaultConnection.UserName, StringComparison.OrdinalIgnoreCase) == 0)
         {
             Project = new UserSelectedProjectSettings(null, null, Project.Type, Project.ClientPath, Project.LocalPath);
         }
     }
     return(Project);
 }
        void RunTask(int Idx)
        {
            DetectProjectSettingsTask Task = Tasks[Idx];

            UserSelectedProjectSettings Project  = Task.SelectedProject;
            PerforceConnection          Perforce = Utility.OverridePerforceSettings(DefaultConnection, Project.ServerAndPort, Project.UserName);

            string TaskErrorMessage;
            bool   bTaskSucceeded = Tasks[Idx].Run(Perforce, out TaskErrorMessage);

            Results[Idx] = new DetectProjectSettingsResult(Tasks[Idx], bTaskSucceeded, TaskErrorMessage);
            Tasks[Idx]   = null;
        }
        public static bool ShowModal(IWin32Window Owner, UserSelectedProjectSettings Project, out DetectProjectSettingsTask NewDetectedProjectSettings, UserSettings Settings, string DataFolder, string CacheFolder, PerforceConnection DefaultConnection, TextWriter Log)
        {
            OpenProjectWindow Window = new OpenProjectWindow(Project, Settings, DataFolder, CacheFolder, DefaultConnection, Log);

            if (Window.ShowDialog(Owner) == DialogResult.OK)
            {
                NewDetectedProjectSettings = Window.DetectedProjectSettings;
                return(true);
            }
            else
            {
                NewDetectedProjectSettings = null;
                return(false);
            }
        }
        public static bool TryParseConfigEntry(string Text, out UserSelectedProjectSettings Project)
        {
            ConfigObject Object = new ConfigObject(Text);

            UserSelectedProjectType Type;

            if (Enum.TryParse(Object.GetValue("Type", ""), out Type))
            {
                string ServerAndPort = Object.GetValue("ServerAndPort", null);
                if (String.IsNullOrWhiteSpace(ServerAndPort))
                {
                    ServerAndPort = null;
                }

                // Fixup for code that was saving server host name rather than DNS entry
                if (ServerAndPort != null && ServerAndPort.Equals("p4-nodeb.epicgames.net:1666", StringComparison.OrdinalIgnoreCase))
                {
                    ServerAndPort = "perforce:1666";
                }

                string UserName = Object.GetValue("UserName", null);
                if (String.IsNullOrWhiteSpace(UserName))
                {
                    UserName = null;
                }

                string LocalPath = Object.GetValue("LocalPath", null);
                if (String.IsNullOrWhiteSpace(LocalPath))
                {
                    LocalPath = null;
                }

                string ClientPath = Object.GetValue("ClientPath", null);
                if (String.IsNullOrWhiteSpace(ClientPath))
                {
                    ClientPath = null;
                }

                if ((Type == UserSelectedProjectType.Client && ClientPath != null) || (Type == UserSelectedProjectType.Local && LocalPath != null))
                {
                    Project = new UserSelectedProjectSettings(ServerAndPort, UserName, Type, ClientPath, LocalPath);
                    return(true);
                }
            }

            Project = null;
            return(false);
        }
 int TryOpenProject(UserSelectedProjectSettings Project, int ReplaceTabIdx, OpenProjectOptions Options = OpenProjectOptions.None)
 {
     using (DetectProjectSettingsTask DetectProjectSettings = new DetectProjectSettingsTask(Project, DataFolder, Log))
     {
         string ErrorMessage;
         if (ModalTask.Execute(this, DetectProjectSettings, "Opening Project", "Opening project, please wait...", out ErrorMessage) != ModalTaskResult.Succeeded)
         {
             if (!String.IsNullOrEmpty(ErrorMessage) && (Options & OpenProjectOptions.Quiet) == 0)
             {
                 CreateErrorPanel(ReplaceTabIdx, Project, ErrorMessage);
             }
             return(-1);
         }
         return(TryOpenProject(DetectProjectSettings, ReplaceTabIdx, Options));
     }
 }
示例#11
0
        public void RequestProjectChange(WorkspaceControl Workspace, UserSelectedProjectSettings Project, bool bModal)
        {
            int TabIdx = TabControl.FindTabIndex(Workspace);

            if (TabIdx != -1 && !Workspace.IsBusy() && CanFocus)
            {
                if (bModal)
                {
                    TryOpenProject(Project, TabIdx);
                }
                else
                {
                    TryOpenProject(Project, TabIdx, OpenProjectOptions.Quiet);
                }
            }
        }
示例#12
0
        public void EditSelectedProject(int TabIdx, UserSelectedProjectSettings SelectedProject)
        {
            DetectProjectSettingsTask DetectedProjectSettings;

            if (OpenProjectWindow.ShowModal(this, SelectedProject, out DetectedProjectSettings, Settings, DataFolder, CacheFolder, Log))
            {
                int NewTabIdx = TryOpenProject(DetectedProjectSettings, TabIdx, OpenProjectOptions.None);
                if (NewTabIdx != -1)
                {
                    TabControl.SelectTab(NewTabIdx);
                    SaveTabSettings();

                    Settings.RecentProjects.RemoveAll(x => x.LocalPath == DetectedProjectSettings.NewSelectedFileName);
                    Settings.RecentProjects.Insert(0, DetectedProjectSettings.SelectedProject);
                    Settings.Save();
                }
            }
        }
示例#13
0
        public static bool TryParseConfigEntry(string Text, out UserSelectedProjectSettings Project)
        {
            ConfigObject Object = new ConfigObject(Text);

            UserSelectedProjectType Type;

            if (Enum.TryParse(Object.GetValue("Type", ""), out Type))
            {
                string ServerAndPort = Object.GetValue("ServerAndPort", null);
                if (String.IsNullOrWhiteSpace(ServerAndPort))
                {
                    ServerAndPort = null;
                }

                string UserName = Object.GetValue("UserName", null);
                if (String.IsNullOrWhiteSpace(UserName))
                {
                    UserName = null;
                }

                string LocalPath = Object.GetValue("LocalPath", null);
                if (String.IsNullOrWhiteSpace(LocalPath))
                {
                    LocalPath = null;
                }

                string ClientPath = Object.GetValue("ClientPath", null);
                if (String.IsNullOrWhiteSpace(ClientPath))
                {
                    ClientPath = null;
                }

                if ((Type == UserSelectedProjectType.Client && ClientPath != null) || (Type == UserSelectedProjectType.Local && LocalPath != null))
                {
                    Project = new UserSelectedProjectSettings(ServerAndPort, UserName, Type, ClientPath, LocalPath);
                    return(true);
                }
            }

            Project = null;
            return(false);
        }
示例#14
0
        public void StreamChangedCallback(WorkspaceControl Workspace)
        {
            if (ChangingWorkspacesRefCount == 0)
            {
                ChangingWorkspacesRefCount++;

                for (int Idx = 0; Idx < TabControl.GetTabCount(); Idx++)
                {
                    if (TabControl.GetTabData(Idx) == Workspace)
                    {
                        UserSelectedProjectSettings Project = Workspace.SelectedProject;
                        if (TryOpenProject(Project, Idx) == -1)
                        {
                            TabControl.RemoveTab(Idx);
                        }
                        break;
                    }
                }

                ChangingWorkspacesRefCount--;
            }
        }
        private bool TryGetSelectedProject(out UserSelectedProjectSettings Project)
        {
            if (WorkspaceRadioBtn.Checked)
            {
                string ClientPath;
                if (TryGetClientPath(out ClientPath))
                {
                    Project = new UserSelectedProjectSettings(ServerAndPortOverride, UserNameOverride, UserSelectedProjectType.Client, ClientPath, null);
                    return(true);
                }
            }
            else
            {
                string LocalPath;
                if (TryGetLocalPath(out LocalPath))
                {
                    Project = new UserSelectedProjectSettings(ServerAndPortOverride, UserNameOverride, UserSelectedProjectType.Local, null, LocalPath);
                    return(true);
                }
            }

            Project = null;
            return(false);
        }
示例#16
0
        AutomationRequestOutput StartAutomatedSync(AutomationRequest Request, bool bForceSync)
        {
            ShowAndActivate();

            BinaryReader Reader      = new BinaryReader(new MemoryStream(Request.Input.Data));
            string       StreamName  = Reader.ReadString();
            string       ProjectPath = Reader.ReadString();

            AutomatedSyncWindow.WorkspaceInfo WorkspaceInfo;
            if (!AutomatedSyncWindow.ShowModal(this, StreamName, ProjectPath, out WorkspaceInfo, Log))
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Canceled));
            }

            if (WorkspaceInfo.bRequiresStreamSwitch)
            {
                // Close any tab containing this window
                for (int ExistingTabIdx = 0; ExistingTabIdx < TabControl.GetTabCount(); ExistingTabIdx++)
                {
                    WorkspaceControl ExistingWorkspace = TabControl.GetTabData(ExistingTabIdx) as WorkspaceControl;
                    if (ExistingWorkspace != null && ExistingWorkspace.ClientName.Equals(WorkspaceInfo.WorkspaceName))
                    {
                        TabControl.RemoveTab(ExistingTabIdx);
                        break;
                    }
                }

                // Switch the stream
                PerforceConnection Perforce = new PerforceConnection(WorkspaceInfo.UserName, WorkspaceInfo.WorkspaceName, WorkspaceInfo.ServerAndPort);
                if (!Perforce.SwitchStream(StreamName, Log))
                {
                    Log.WriteLine("Unable to switch stream");
                    return(new AutomationRequestOutput(AutomationRequestResult.Error));
                }
            }

            UserSelectedProjectSettings SelectedProject = new UserSelectedProjectSettings(WorkspaceInfo.ServerAndPort, WorkspaceInfo.UserName, UserSelectedProjectType.Client, String.Format("//{0}{1}", WorkspaceInfo.WorkspaceName, ProjectPath), null);

            int TabIdx = TryOpenProject(SelectedProject, -1, OpenProjectOptions.None);

            if (TabIdx == -1)
            {
                Log.WriteLine("Unable to open project");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            WorkspaceControl Workspace = TabControl.GetTabData(TabIdx) as WorkspaceControl;

            if (Workspace == null)
            {
                Log.WriteLine("Workspace was unable to open");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            if (!bForceSync && Workspace.CanLaunchEditor())
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Ok, Encoding.UTF8.GetBytes(Workspace.SelectedFileName)));
            }

            Workspace.AddStartupCallback((Control, bCancel) => StartAutomatedSyncAfterStartup(Control, bCancel, Request));
            return(null);
        }
        public bool Run(PerforceConnection Perforce, TextWriter Log, out string ErrorMessage)
        {
            // Get the perforce server settings
            PerforceInfoRecord PerforceInfo;

            if (!Perforce.Info(out PerforceInfo, Log))
            {
                ErrorMessage = String.Format("Couldn't get Perforce server info");
                return(false);
            }

            // Configure the time zone
            ServerTimeZone = PerforceInfo.ServerTimeZone;

            // If we're using the legacy path of specifying a file, figure out the workspace name now
            if (SelectedProject.Type == UserSelectedProjectType.Client)
            {
                // Get the client path
                NewSelectedClientFileName = SelectedProject.ClientPath;

                // Get the client name
                string ClientName;
                if (!PerforceUtils.TryGetClientName(NewSelectedClientFileName, out ClientName))
                {
                    ErrorMessage = String.Format("Couldn't get client name from {0}", NewSelectedClientFileName);
                    return(false);
                }

                // Create the client
                PerforceClient = new PerforceConnection(Perforce.UserName, ClientName, Perforce.ServerAndPort);

                // Figure out the path on the client
                if (!PerforceClient.ConvertToLocalPath(NewSelectedClientFileName, out NewSelectedFileName, Log))
                {
                    ErrorMessage = String.Format("Couldn't get client path for {0}", NewSelectedFileName);
                    return(false);
                }
            }
            else if (SelectedProject.Type == UserSelectedProjectType.Local)
            {
                // Use the path as the selected filename
                NewSelectedFileName = SelectedProject.LocalPath;

                // Make sure the project exists
                if (!File.Exists(SelectedProject.LocalPath))
                {
                    ErrorMessage = String.Format("{0} does not exist.", SelectedProject.LocalPath);
                    return(false);
                }

                // Find all the clients on this machine
                Log.WriteLine("Enumerating clients on local machine...");
                List <PerforceClientRecord> Clients;
                if (!Perforce.FindClients(out Clients, Log))
                {
                    ErrorMessage = String.Format("Couldn't find any clients for this host.");
                    return(false);
                }

                // Find any clients which are valid. If this is not exactly one, we should fail.
                List <PerforceConnection> CandidateClients = new List <PerforceConnection>();
                foreach (PerforceClientRecord Client in Clients)
                {
                    // Make sure the client is well formed
                    if (!String.IsNullOrEmpty(Client.Name) && (!String.IsNullOrEmpty(Client.Host) || !String.IsNullOrEmpty(Client.Owner)) && !String.IsNullOrEmpty(Client.Root))
                    {
                        // Require either a username or host name match
                        if ((String.IsNullOrEmpty(Client.Host) || String.Compare(Client.Host, PerforceInfo.HostName, StringComparison.InvariantCultureIgnoreCase) == 0) && (String.IsNullOrEmpty(Client.Owner) || String.Compare(Client.Owner, PerforceInfo.UserName, StringComparison.InvariantCultureIgnoreCase) == 0))
                        {
                            if (!Utility.SafeIsFileUnderDirectory(NewSelectedFileName, Client.Root))
                            {
                                Log.WriteLine("Rejecting {0} due to root mismatch ({1})", Client.Name, Client.Root);
                                continue;
                            }

                            PerforceConnection CandidateClient = new PerforceConnection(PerforceInfo.UserName, Client.Name, Perforce.ServerAndPort);

                            bool bFileExists;
                            if (!CandidateClient.FileExists(NewSelectedFileName, out bFileExists, Log) || !bFileExists)
                            {
                                Log.WriteLine("Rejecting {0} due to file not existing in workspace", Client.Name);
                                continue;
                            }

                            List <PerforceFileRecord> Records;
                            if (!CandidateClient.Stat(NewSelectedFileName, out Records, Log))
                            {
                                Log.WriteLine("Rejecting {0} due to {1} not in depot", Client.Name, NewSelectedFileName);
                                continue;
                            }

                            Records.RemoveAll(x => !x.IsMapped);
                            if (Records.Count == 0)
                            {
                                Log.WriteLine("Rejecting {0} due to {1} matching records", Client.Name, Records.Count);
                                continue;
                            }

                            Log.WriteLine("Found valid client {0}", Client.Name);
                            CandidateClients.Add(CandidateClient);
                        }
                    }
                }

                // Check there's only one client
                if (CandidateClients.Count == 0)
                {
                    ErrorMessage = String.Format("Couldn't find any Perforce workspace containing {0}. Check your connection settings.", NewSelectedFileName);
                    return(false);
                }
                else if (CandidateClients.Count > 1)
                {
                    ErrorMessage = String.Format("Found multiple workspaces containing {0}:\n\n{1}\n\nCannot determine which to use.", Path.GetFileName(NewSelectedFileName), String.Join("\n", CandidateClients.Select(x => x.ClientName)));
                    return(false);
                }

                // Take the client we've chosen
                PerforceClient = CandidateClients[0];

                // Get the client path for the project file
                if (!PerforceClient.ConvertToClientPath(NewSelectedFileName, out NewSelectedClientFileName, Log))
                {
                    ErrorMessage = String.Format("Couldn't get client path for {0}", NewSelectedFileName);
                    return(false);
                }
            }
            else
            {
                throw new InvalidDataException("Invalid selected project type");
            }

            // Normalize the filename
            NewSelectedFileName = Path.GetFullPath(NewSelectedFileName).Replace('/', Path.DirectorySeparatorChar);

            // Make sure the path case is correct. This can cause UBT intermediates to be out of date if the case mismatches.
            NewSelectedFileName = Utility.GetPathWithCorrectCase(new FileInfo(NewSelectedFileName));

            // Update the selected project with all the data we've found
            SelectedProject = new UserSelectedProjectSettings(Perforce.ServerAndPort, Perforce.UserName, SelectedProject.Type, NewSelectedClientFileName, NewSelectedFileName);

            // Figure out where the engine is in relation to it
            for (int EndIdx = NewSelectedClientFileName.Length - 1;; EndIdx--)
            {
                if (EndIdx < 2)
                {
                    ErrorMessage = String.Format("Could not find engine in Perforce relative to project path ({0})", NewSelectedClientFileName);
                    return(false);
                }
                if (NewSelectedClientFileName[EndIdx] == '/')
                {
                    bool bFileExists;
                    if (PerforceClient.FileExists(NewSelectedClientFileName.Substring(0, EndIdx) + "/Engine/Build/Build.version", out bFileExists, Log) && bFileExists)
                    {
                        BranchClientPath = NewSelectedClientFileName.Substring(0, EndIdx);
                        break;
                    }
                }
            }
            Log.WriteLine("Found branch root at {0}", BranchClientPath);

            // Get the local branch root
            string BuildVersionPath;

            if (!PerforceClient.ConvertToLocalPath(BranchClientPath + "/Engine/Build/Build.version", out BuildVersionPath, Log))
            {
                ErrorMessage = String.Format("Couldn't get local path for Engine/Build/Build.version");
                return(false);
            }
            BranchDirectoryName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(BuildVersionPath), "..", ".."));

            // Find the editor target for this project
            if (NewSelectedFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase))
            {
                List <PerforceFileRecord> Files;
                if (PerforceClient.FindFiles(PerforceUtils.GetClientOrDepotDirectoryName(NewSelectedClientFileName) + "/Source/*Editor.Target.cs", out Files, Log) && Files.Count >= 1)
                {
                    PerforceFileRecord File = Files.FirstOrDefault(x => x.Action == null || !x.Action.Contains("delete"));
                    if (File != null)
                    {
                        string DepotPath = File.DepotPath;
                        NewProjectEditorTarget = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(DepotPath.Substring(DepotPath.LastIndexOf('/') + 1)));
                        Log.WriteLine("Using {0} as editor target name (from {1})", NewProjectEditorTarget, Files[0]);
                    }
                }
                if (NewProjectEditorTarget == null)
                {
                    Log.WriteLine("Couldn't find any editor targets for this project.");
                }
            }

            // Get a unique name for the project that's selected. For regular branches, this can be the depot path. For streams, we want to include the stream name to encode imports.
            if (PerforceClient.GetActiveStream(out StreamName, Log))
            {
                string ExpectedPrefix = String.Format("//{0}/", PerforceClient.ClientName);
                if (!NewSelectedClientFileName.StartsWith(ExpectedPrefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    ErrorMessage = String.Format("Unexpected client path; expected '{0}' to begin with '{1}'", NewSelectedClientFileName, ExpectedPrefix);
                    return(false);
                }
                string StreamPrefix;
                if (!TryGetStreamPrefix(PerforceClient, StreamName, Log, out StreamPrefix))
                {
                    ErrorMessage = String.Format("Failed to get stream info for {0}", StreamName);
                    return(false);
                }
                NewSelectedProjectIdentifier = String.Format("{0}/{1}", StreamPrefix, NewSelectedClientFileName.Substring(ExpectedPrefix.Length));
            }
            else
            {
                if (!PerforceClient.ConvertToDepotPath(NewSelectedClientFileName, out NewSelectedProjectIdentifier, Log))
                {
                    ErrorMessage = String.Format("Couldn't get depot path for {0}", NewSelectedFileName);
                    return(false);
                }
            }

            // Read the project logo
            if (NewSelectedFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase))
            {
                string LogoFileName = Path.Combine(Path.GetDirectoryName(NewSelectedFileName), "Build", "UnrealGameSync.png");
                if (File.Exists(LogoFileName))
                {
                    try
                    {
                        // Duplicate the image, otherwise we'll leave the file locked
                        using (Image Image = Image.FromFile(LogoFileName))
                        {
                            ProjectLogo = new Bitmap(Image);
                        }
                    }
                    catch
                    {
                        ProjectLogo = null;
                    }
                }
            }

            // Figure out if it's an enterprise project
            List <string> ProjectLines;

            if (NewSelectedClientFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase) && PerforceClient.Print(NewSelectedClientFileName, out ProjectLines, Log))
            {
                string Text = String.Join("\n", ProjectLines);
                bIsEnterpriseProject = Utility.IsEnterpriseProjectFromText(Text);
            }

            // Read the initial config file
            LocalConfigFiles        = new List <KeyValuePair <string, DateTime> >();
            LatestProjectConfigFile = PerforceMonitor.ReadProjectConfigFile(PerforceClient, BranchClientPath, NewSelectedClientFileName, LocalConfigFiles, Log);

            // Succeed!
            ErrorMessage = null;
            return(true);
        }
        public UserSettings(string InFileName)
        {
            FileName = InFileName;
            if (File.Exists(FileName))
            {
                ConfigFile.Load(FileName);
            }

            // General settings
            Version                = (UserSettingsVersion)ConfigFile.GetValue("General.Version", (int)UserSettingsVersion.Initial);
            bBuildAfterSync        = (ConfigFile.GetValue("General.BuildAfterSync", "1") != "0");
            bRunAfterSync          = (ConfigFile.GetValue("General.RunAfterSync", "1") != "0");
            bSyncPrecompiledEditor = (ConfigFile.GetValue("General.SyncPrecompiledEditor", "0") != "0");
            bOpenSolutionAfterSync = (ConfigFile.GetValue("General.OpenSolutionAfterSync", "0") != "0");
            bShowLogWindow         = (ConfigFile.GetValue("General.ShowLogWindow", false));
            bAutoResolveConflicts  = (ConfigFile.GetValue("General.AutoResolveConflicts", "1") != "0");
            bUseIncrementalBuilds  = ConfigFile.GetValue("General.IncrementalBuilds", true);
            bShowUnreviewedChanges = ConfigFile.GetValue("General.ShowUnreviewed", true);
            bShowAutomatedChanges  = ConfigFile.GetValue("General.ShowAutomated", false);
            bShowLocalTimes        = ConfigFile.GetValue("General.ShowLocalTimes", false);
            bKeepInTray            = ConfigFile.GetValue("General.KeepInTray", true);
            int.TryParse(ConfigFile.GetValue("General.FilterIndex", "0"), out FilterIndex);

            string LastProjectString = ConfigFile.GetValue("General.LastProject", null);

            if (LastProjectString != null)
            {
                UserSelectedProjectSettings.TryParseConfigEntry(LastProjectString, out LastProject);
            }
            else
            {
                string LastProjectFileName = ConfigFile.GetValue("General.LastProjectFileName", null);
                if (LastProjectFileName != null)
                {
                    LastProject = new UserSelectedProjectSettings(null, null, UserSelectedProjectType.Local, null, LastProjectFileName);
                }
            }

            OpenProjects   = ReadProjectList("General.OpenProjects", "General.OpenProjectFileNames");
            RecentProjects = ReadProjectList("General.RecentProjects", "General.OtherProjectFileNames");

            SyncView = ConfigFile.GetValues("General.SyncFilter", new string[0]);
            SyncExcludedCategories        = ConfigFile.GetGuidValues("General.SyncExcludedCategories", new Guid[0]);
            bSyncAllProjects              = ConfigFile.GetValue("General.SyncAllProjects", false);
            bIncludeAllProjectsInSolution = ConfigFile.GetValue("General.IncludeAllProjectsInSolution", false);
            if (!Enum.TryParse(ConfigFile.GetValue("General.SyncType", ""), out SyncType))
            {
                SyncType = LatestChangeType.Good;
            }

            // Build configuration
            string CompiledEditorBuildConfigName = ConfigFile.GetValue("General.BuildConfig", "");

            if (!Enum.TryParse(CompiledEditorBuildConfigName, true, out CompiledEditorBuildConfig))
            {
                CompiledEditorBuildConfig = BuildConfig.DebugGame;
            }

            // Tab names
            string TabLabelsValue = ConfigFile.GetValue("General.TabLabels", "");

            if (!Enum.TryParse(TabLabelsValue, true, out TabLabels))
            {
                TabLabels = TabLabels.Stream;
            }

            // Editor arguments
            string[] Arguments = ConfigFile.GetValues("General.EditorArguments", new string[] { "0:-log", "0:-fastload" });
            foreach (string Argument in Arguments)
            {
                if (Argument.StartsWith("0:"))
                {
                    EditorArguments.Add(new Tuple <string, bool>(Argument.Substring(2), false));
                }
                else if (Argument.StartsWith("1:"))
                {
                    EditorArguments.Add(new Tuple <string, bool>(Argument.Substring(2), true));
                }
                else
                {
                    EditorArguments.Add(new Tuple <string, bool>(Argument, true));
                }
            }
            bEditorArgumentsPrompt = ConfigFile.GetValue("General.EditorArgumentsPrompt", false);

            // Window settings
            bWindowVisible = ConfigFile.GetValue("Window.Visible", true);
            if (!Enum.TryParse(ConfigFile.GetValue("Window.State", ""), true, out WindowState))
            {
                WindowState = FormWindowState.Normal;
            }
            WindowBounds = ParseRectangleValue(ConfigFile.GetValue("Window.Bounds", ""));

            // Schedule settings
            bScheduleEnabled = ConfigFile.GetValue("Schedule.Enabled", false);
            if (!TimeSpan.TryParse(ConfigFile.GetValue("Schedule.Time", ""), out ScheduleTime))
            {
                ScheduleTime = new TimeSpan(6, 0, 0);
            }
            if (!Enum.TryParse(ConfigFile.GetValue("Schedule.Change", ""), out ScheduleChange))
            {
                ScheduleChange = LatestChangeType.Good;
            }
            ScheduleAnyOpenProject = ConfigFile.GetValue("Schedule.AnyOpenProject", true);
            ScheduleProjects       = ReadProjectList("Schedule.Projects", "Schedule.ProjectFileNames");

            // Notification settings
            NotifyUnassignedMinutes     = ConfigFile.GetValue("Notifications.NotifyUnassignedMinutes", -1);
            NotifyUnacknowledgedMinutes = ConfigFile.GetValue("Notifications.NotifyUnacknowledgedMinutes", -1);
            NotifyUnresolvedMinutes     = ConfigFile.GetValue("Notifications.NotifyUnresolvedMinutes", -1);

            // Perforce settings
            if (!int.TryParse(ConfigFile.GetValue("Perforce.NumRetries", "0"), out SyncOptions.NumRetries))
            {
                SyncOptions.NumRetries = 0;
            }
            if (!int.TryParse(ConfigFile.GetValue("Perforce.NumThreads", "0"), out SyncOptions.NumThreads))
            {
                SyncOptions.NumThreads = 0;
            }
            if (!int.TryParse(ConfigFile.GetValue("Perforce.TcpBufferSize", "0"), out SyncOptions.TcpBufferSize))
            {
                SyncOptions.TcpBufferSize = 0;
            }
        }
 public ErrorPanel(UserSelectedProjectSettings InSelectedProject)
 {
     SelectedProject = InSelectedProject;
     SetProjectLogo(Properties.Resources.DefaultErrorLogo, false);
 }
        public bool Run(PerforceConnection Perforce, TextWriter Log, out string ErrorMessage)
        {
            // Use the cached client path to the file if it's available; it's much quicker than trying to find the correct workspace.
            if (!String.IsNullOrEmpty(SelectedProject.ClientPath))
            {
                // Get the client path
                NewSelectedClientFileName = SelectedProject.ClientPath;

                // Get the client name
                string ClientName;
                if (!PerforceUtils.TryGetClientName(NewSelectedClientFileName, out ClientName))
                {
                    ErrorMessage = String.Format("Couldn't get client name from {0}", NewSelectedClientFileName);
                    return(false);
                }

                // Create the client
                PerforceClient = new PerforceConnection(Perforce.UserName, ClientName, Perforce.ServerAndPort);

                // Figure out the path on the client. Use the cached location if it's valid.
                if (SelectedProject.LocalPath != null && File.Exists(SelectedProject.LocalPath))
                {
                    NewSelectedFileName = SelectedProject.LocalPath;
                }
                else
                {
                    if (!PerforceClient.ConvertToLocalPath(NewSelectedClientFileName, out NewSelectedFileName, Log))
                    {
                        ErrorMessage = String.Format("Couldn't get client path for {0}", NewSelectedClientFileName);
                        return(false);
                    }
                }
            }
            else
            {
                // Get the perforce server settings
                PerforceInfoRecord PerforceInfo;
                if (!Perforce.Info(out PerforceInfo, Log))
                {
                    ErrorMessage = String.Format("Couldn't get Perforce server info");
                    return(false);
                }

                // Use the path as the selected filename
                NewSelectedFileName = SelectedProject.LocalPath;

                // Make sure the project exists
                if (!File.Exists(SelectedProject.LocalPath))
                {
                    ErrorMessage = String.Format("{0} does not exist.", SelectedProject.LocalPath);
                    return(false);
                }

                // Find all the clients for this user
                Log.WriteLine("Enumerating clients for {0}...", PerforceInfo.UserName);

                List <PerforceClientRecord> Clients;
                if (!Perforce.FindClients(PerforceInfo.UserName, out Clients, Log))
                {
                    ErrorMessage = String.Format("Couldn't find any clients for this host.");
                    return(false);
                }

                List <PerforceConnection> CandidateClients = FilterClients(Clients, Perforce.ServerAndPort, PerforceInfo.HostName, PerforceInfo.UserName);
                if (CandidateClients.Count == 0)
                {
                    // Search through all workspaces. We may find a suitable workspace which is for any user.
                    Log.WriteLine("Enumerating shared clients...");
                    if (!Perforce.FindClients("", out Clients, Log))
                    {
                        ErrorMessage = "Failed to enumerate clients.";
                        return(false);
                    }

                    // Filter this list of clients
                    CandidateClients = FilterClients(Clients, Perforce.ServerAndPort, PerforceInfo.HostName, PerforceInfo.UserName);

                    // If we still couldn't find any, fail.
                    if (CandidateClients.Count == 0)
                    {
                        ErrorMessage = String.Format("Couldn't find any Perforce workspace containing {0}. Check your connection settings.", NewSelectedFileName);
                        return(false);
                    }
                }

                // Check there's only one client
                if (CandidateClients.Count > 1)
                {
                    ErrorMessage = String.Format("Found multiple workspaces containing {0}:\n\n{1}\n\nCannot determine which to use.", Path.GetFileName(NewSelectedFileName), String.Join("\n", CandidateClients.Select(x => x.ClientName)));
                    return(false);
                }

                // Take the client we've chosen
                PerforceClient = CandidateClients[0];

                // Get the client path for the project file
                if (!PerforceClient.ConvertToClientPath(NewSelectedFileName, out NewSelectedClientFileName, Log))
                {
                    ErrorMessage = String.Format("Couldn't get client path for {0}", NewSelectedFileName);
                    return(false);
                }
            }

            // Normalize the filename
            NewSelectedFileName = Path.GetFullPath(NewSelectedFileName).Replace('/', Path.DirectorySeparatorChar);

            // Make sure the path case is correct. This can cause UBT intermediates to be out of date if the case mismatches.
            NewSelectedFileName = Utility.GetPathWithCorrectCase(new FileInfo(NewSelectedFileName));

            // Update the selected project with all the data we've found
            SelectedProject = new UserSelectedProjectSettings(SelectedProject.ServerAndPort, SelectedProject.UserName, SelectedProject.Type, NewSelectedClientFileName, NewSelectedFileName);

            // Figure out where the engine is in relation to it
            int EndIdx = NewSelectedClientFileName.Length - 1;

            if (EndIdx != -1 && NewSelectedClientFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase))
            {
                EndIdx = NewSelectedClientFileName.LastIndexOf('/') - 1;
            }
            for (;; EndIdx--)
            {
                if (EndIdx < 2)
                {
                    ErrorMessage = String.Format("Could not find engine in Perforce relative to project path ({0})", NewSelectedClientFileName);
                    return(false);
                }
                if (NewSelectedClientFileName[EndIdx] == '/')
                {
                    List <PerforceFileRecord> FileRecords;
                    if (PerforceClient.Stat(NewSelectedClientFileName.Substring(0, EndIdx) + "/Engine/Build/Build.version", out FileRecords, Log) && FileRecords.Count > 0)
                    {
                        if (FileRecords[0].ClientPath == null)
                        {
                            ErrorMessage = String.Format("Missing client path for {0}", FileRecords[0].DepotPath);
                            return(false);
                        }

                        BranchClientPath    = NewSelectedClientFileName.Substring(0, EndIdx);
                        BranchDirectoryName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(FileRecords[0].ClientPath), "..", ".."));
                        break;
                    }
                }
            }
            Log.WriteLine("Found branch root at {0}", BranchClientPath);

            // Find the editor target for this project
            if (NewSelectedFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase))
            {
                List <PerforceFileRecord> Files;
                if (PerforceClient.FindFiles(PerforceUtils.GetClientOrDepotDirectoryName(NewSelectedClientFileName) + "/Source/*Editor.Target.cs", out Files, Log) && Files.Count >= 1)
                {
                    string DepotPath = Files[0].DepotPath;
                    NewProjectEditorTarget = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(DepotPath.Substring(DepotPath.LastIndexOf('/') + 1)));
                    Log.WriteLine("Using {0} as editor target name (from {1})", NewProjectEditorTarget, Files[0]);
                }
                if (NewProjectEditorTarget == null)
                {
                    Log.WriteLine("Couldn't find any editor targets for this project.");
                }
            }

            // Get a unique name for the project that's selected. For regular branches, this can be the depot path. For streams, we want to include the stream name to encode imports.
            if (PerforceClient.GetActiveStream(out StreamName, Log))
            {
                string ExpectedPrefix = String.Format("//{0}/", PerforceClient.ClientName);
                if (!NewSelectedClientFileName.StartsWith(ExpectedPrefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    ErrorMessage = String.Format("Unexpected client path; expected '{0}' to begin with '{1}'", NewSelectedClientFileName, ExpectedPrefix);
                    return(false);
                }
                string StreamPrefix;
                if (!TryGetStreamPrefix(PerforceClient, StreamName, Log, out StreamPrefix))
                {
                    ErrorMessage = String.Format("Failed to get stream info for {0}", StreamName);
                    return(false);
                }
                NewSelectedProjectIdentifier = String.Format("{0}/{1}", StreamPrefix, NewSelectedClientFileName.Substring(ExpectedPrefix.Length));
            }
            else
            {
                if (!PerforceClient.ConvertToDepotPath(NewSelectedClientFileName, out NewSelectedProjectIdentifier, Log))
                {
                    ErrorMessage = String.Format("Couldn't get depot path for {0}", NewSelectedFileName);
                    return(false);
                }
            }

            // Read the project logo
            if (NewSelectedFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase))
            {
                string LogoFileName = Path.Combine(Path.GetDirectoryName(NewSelectedFileName), "Build", "UnrealGameSync.png");
                if (File.Exists(LogoFileName))
                {
                    try
                    {
                        // Duplicate the image, otherwise we'll leave the file locked
                        using (Image Image = Image.FromFile(LogoFileName))
                        {
                            ProjectLogo = new Bitmap(Image);
                        }
                    }
                    catch
                    {
                        ProjectLogo = null;
                    }
                }
            }

            // Figure out if it's an enterprise project. Use the synced version if we have it.
            if (NewSelectedClientFileName.EndsWith(".uproject", StringComparison.InvariantCultureIgnoreCase))
            {
                string Text;
                if (File.Exists(NewSelectedFileName))
                {
                    Text = File.ReadAllText(NewSelectedFileName);
                }
                else
                {
                    List <string> ProjectLines;
                    if (!PerforceClient.Print(NewSelectedClientFileName, out ProjectLines, Log))
                    {
                        ErrorMessage = String.Format("Unable to get contents of {0}", NewSelectedClientFileName);
                        return(false);
                    }
                    Text = String.Join("\n", ProjectLines);
                }
                bIsEnterpriseProject = Utility.IsEnterpriseProjectFromText(Text);
            }

            // Read the initial config file
            LocalConfigFiles        = new List <KeyValuePair <string, DateTime> >();
            LatestProjectConfigFile = PerforceMonitor.ReadProjectConfigFile(PerforceClient, BranchClientPath, NewSelectedClientFileName, CacheFolder, LocalConfigFiles, Log);

            // Succeed!
            ErrorMessage = null;
            return(true);
        }
示例#21
0
        private void CreateErrorPanel(int ReplaceTabIdx, UserSelectedProjectSettings Project, string Message)
        {
            Log.WriteLine(Message ?? "Unknown error");

            ErrorPanel ErrorPanel = new ErrorPanel(Project);

            ErrorPanel.Parent      = TabPanel;
            ErrorPanel.BorderStyle = BorderStyle.FixedSingle;
            ErrorPanel.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250)))));
            ErrorPanel.Location    = new Point(0, 0);
            ErrorPanel.Dock        = DockStyle.Fill;
            ErrorPanel.Hide();

            string SummaryText = String.Format("Unable to open '{0}'.", Project.ToString());

            int NewContentWidth = Math.Max(TextRenderer.MeasureText(SummaryText, ErrorPanel.Font).Width, 400);

            if (!String.IsNullOrEmpty(Message))
            {
                NewContentWidth = Math.Max(NewContentWidth, TextRenderer.MeasureText(Message, ErrorPanel.Font).Width);
            }

            ErrorPanel.SetContentWidth(NewContentWidth);

            List <StatusLine> Lines = new List <StatusLine>();

            StatusLine SummaryLine = new StatusLine();

            SummaryLine.AddText(SummaryText);
            Lines.Add(SummaryLine);

            if (!String.IsNullOrEmpty(Message))
            {
                Lines.Add(new StatusLine()
                {
                    LineHeight = 0.5f
                });

                foreach (string MessageLine in Message.Split('\n'))
                {
                    StatusLine ErrorLine = new StatusLine();
                    ErrorLine.AddText(MessageLine);
                    ErrorLine.LineHeight = 0.8f;
                    Lines.Add(ErrorLine);
                }
            }

            Lines.Add(new StatusLine()
            {
                LineHeight = 0.5f
            });

            StatusLine ActionLine = new StatusLine();

            ActionLine.AddLink("Retry", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { TryOpenProject(Project, TabControl.FindTabIndex(ErrorPanel)); })); });
            ActionLine.AddText(" | ");
            ActionLine.AddLink("Settings", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { EditSelectedProject(ErrorPanel); })); });
            ActionLine.AddText(" | ");
            ActionLine.AddLink("Close", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { TabControl.RemoveTab(TabControl.FindTabIndex(ErrorPanel)); })); });
            Lines.Add(ActionLine);

            ErrorPanel.Set(Lines, null, null, null);

            string NewProjectName = "Unknown";

            if (Project.Type == UserSelectedProjectType.Client && Project.ClientPath != null)
            {
                NewProjectName = Project.ClientPath.Substring(Project.ClientPath.LastIndexOf('/') + 1);
            }
            if (Project.Type == UserSelectedProjectType.Local && Project.LocalPath != null)
            {
                NewProjectName = Project.LocalPath.Substring(Project.LocalPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
            }

            string NewTabName = String.Format("Error: {0}", NewProjectName);

            if (ReplaceTabIdx == -1)
            {
                int TabIdx = TabControl.InsertTab(-1, NewTabName, ErrorPanel);
                TabControl.SelectTab(TabIdx);
            }
            else
            {
                TabControl.InsertTab(ReplaceTabIdx + 1, NewTabName, ErrorPanel);
                TabControl.RemoveTab(ReplaceTabIdx);
                TabControl.SelectTab(ReplaceTabIdx);
            }

            UpdateProgress();
        }