Ejemplo n.º 1
0
        public Result Commit()
        {
            if (OpenFiles.Any(x => (x.OpenMode & OpenMode.Write) != 0))
            {
                return(ResultFs.WriteModeFileNotClosed.Log());
            }

            return(FileSystem.Commit());
        }
Ejemplo n.º 2
0
        public void Commit()
        {
            if (OpenFiles.Any(x => (x.OpenMode & OpenMode.Write) != 0))
            {
                ThrowHelper.ThrowResult(ResultFs.WritableFileOpen);
            }

            FileSystem.Commit();
        }
Ejemplo n.º 3
0
        public static ConfigFile ReadProjectConfigFile(PerforceConnection Perforce, string BranchClientPath, string SelectedClientFileName, List <KeyValuePair <string, DateTime> > LocalConfigFiles, TextWriter Log)
        {
            List <string> ConfigFilePaths = Utility.GetConfigFileLocations(BranchClientPath, SelectedClientFileName, '/');

            List <PerforceFileRecord> OpenFiles;

            Perforce.GetOpenFiles(String.Format("{0}/....ini", BranchClientPath), out OpenFiles, Log);

            ConfigFile ProjectConfig = new ConfigFile();

            foreach (string ConfigFilePath in ConfigFilePaths)
            {
                List <string> Lines = null;

                // If this file is open for edit, read the local version
                if (OpenFiles != null && OpenFiles.Any(x => x.ClientPath.Equals(ConfigFilePath, StringComparison.InvariantCultureIgnoreCase)))
                {
                    try
                    {
                        string LocalFileName;
                        if (Perforce.ConvertToLocalPath(ConfigFilePath, out LocalFileName, Log))
                        {
                            DateTime LastModifiedTime = File.GetLastWriteTimeUtc(LocalFileName);
                            LocalConfigFiles.Add(new KeyValuePair <string, DateTime>(LocalFileName, LastModifiedTime));
                            Lines = File.ReadAllLines(LocalFileName).ToList();
                        }
                    }
                    catch (Exception Ex)
                    {
                        Log.WriteLine("Failed to read local config file for {0}: {1}", ConfigFilePath, Ex.ToString());
                    }
                }

                // Otherwise try to get it from perforce
                if (Lines == null)
                {
                    Perforce.Print(ConfigFilePath, out Lines, Log);
                }

                // Merge the text with the config file
                if (Lines != null)
                {
                    try
                    {
                        ProjectConfig.Parse(Lines.ToArray());
                        Log.WriteLine("Read config file from {0}", ConfigFilePath);
                    }
                    catch (Exception Ex)
                    {
                        Log.WriteLine("Failed to read config file from {0}: {1}", ConfigFilePath, Ex.ToString());
                    }
                }
            }
            return(ProjectConfig);
        }
Ejemplo n.º 4
0
        bool HasModifiedSourceFiles()
        {
            List <PerforceFileRecord> OpenFiles;

            if (!Perforce.GetOpenFiles(ClientRootPath + "/...", out OpenFiles, Log))
            {
                return(true);
            }
            if (OpenFiles.Any(x => x.DepotPath.IndexOf("/Source/", StringComparison.InvariantCultureIgnoreCase) != -1))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Opens a file from the given filename.
        /// </summary>
        /// <param name="filename">Full path of the file to open.</param>
        /// <param name="modelType">Type of the model of the file.</param>
        /// <remarks>This overload is intended to open files on disk, using a specific file type, that are not associated with a project.
        /// To open a project file, use <see cref="OpenFile(Object, Project)"/>.
        /// To open a file that is not necessarily on disk, use <see cref="OpenFile(Object, Boolean)"/>.
        /// To open a file, auto-detecting the file type, use <see cref="OpenFile(String)"/>.
        ///
        /// When the file is closed, the underlying model will be disposed.</remarks>
        public virtual async Task OpenFile(string filename, TypeInfo modelType)
        {
            var model = await IOHelper.OpenFile(filename, modelType, CurrentPluginManager);

            if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model)))
            {
                var wrapper = CreateViewModel(model);
                wrapper.Filename       = filename;
                wrapper.DisposeOnClose = true;
                OpenFiles.Add(wrapper);
                FileOpened?.Invoke(this, new FileOpenedEventArguments {
                    File = model, FileViewModel = wrapper, DisposeOnExit = true
                });
            }
        }
        /// <summary>
        /// Opens the given file
        /// </summary>
        /// <param name="model">The model to open</param>
        /// <param name="disposeOnClose">True to call the file's dispose method (if IDisposable) when closed.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is null.</exception>
        public virtual void OpenFile(object model, bool disposeOnClose)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model)))
            {
                var wrapper = CreateViewModel(model);
                wrapper.DisposeOnClose = disposeOnClose;
                OpenFiles.Add(wrapper);
                FileOpened?.Invoke(this, new FileOpenedEventArguments {
                    File = model, FileViewModel = wrapper, DisposeOnExit = disposeOnClose
                });
            }
        }
        /// <summary>
        /// Opens the given file
        /// </summary>
        /// <param name="model">File to open</param>
        /// <param name="parentProject">Project the file belongs to.  If the file does not belong to a project, don't use this overload.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> or <paramref name="parentProject"/> is null.</exception>
        public virtual void OpenFile(object model, Project parentProject)
        {
            if (ReferenceEquals(model, null))
            {
                throw (new ArgumentNullException(nameof(model)));
            }
            if (ReferenceEquals(parentProject, null))
            {
                throw (new ArgumentNullException(nameof(parentProject)));
            }

            if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model)))
            {
                var wrapper = CreateViewModel(model);
                wrapper.DisposeOnClose = false;
                wrapper.ParentProject  = parentProject;
                OpenFiles.Add(wrapper);
                FileOpened?.Invoke(this, new FileOpenedEventArguments {
                    File = model, FileViewModel = wrapper, DisposeOnExit = false, ParentProject = parentProject
                });
            }
        }
Ejemplo n.º 8
0
        public bool QueryCloseAll()
        {
            if (!OpenFiles.Any(file => file.IsModified))
            {
                return(true);
            }

            var result = MessageBoxService.ShowMessage("Save modified files before exit?",
                                                       Constants.AppTitle, MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                foreach (var file in OpenFiles)
                {
                    if (file.IsModified)
                    {
                        file.SaveInternal();
                    }
                }
                return(true);
            }

            return(result == MessageBoxResult.No);
        }