DirStat() public static méthode

Given a fully qualified path to a local directory, return the stat on that folder
public static DirStat ( string path ) : DirStatType
path string
Résultat DirStatType
        /// <summary>
        /// Selection of the repo items has changed
        /// Update button enables and common path fields correspondingly
        /// </summary>
        private void ListSelectedIndexChanged(object sender, EventArgs e)
        {
            // Delete button is enabled when one or more repos are selected
            btDelete.Enabled = list.SelectedItems.Count > 0;

            // Enable buttons that are defined to work when only one repo is selected
            btLocate.Enabled = btCreate.Enabled = list.SelectedItems.Count == 1;

            // Create repo should be disabled on a valid git repo
            if (btCreate.Enabled)
            {
                btCreate.Enabled = ClassUtils.DirStat(list.SelectedItems[0].Text) != ClassUtils.DirStatType.Git;
            }

            // Extract common path prefix of all selected repos - only if 2 or more repos are selected
            btBrowse.Enabled  = list.SelectedItems.Count > 1;
            textRootPath.Text = "";
            if (list.SelectedItems.Count > 1)
            {
                // Use the first path as the longest known so far
                List <String> commonPath = list.SelectedItems[0].Text.Split(Path.DirectorySeparatorChar).ToList();
                // Each successive path will make the "commonPath" shorter
                for (int i = 1; i < list.SelectedItems.Count; i++)
                {
                    String[]      nextStr   = list.SelectedItems[i].Text.Split(Path.DirectorySeparatorChar);
                    List <String> newCommon = new List <string>();
                    for (int j = 0; j < nextStr.Count() && j < commonPath.Count(); j++)
                    {
                        if (commonPath[j] == nextStr[j])
                        {
                            newCommon.Add(commonPath[j]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    commonPath = newCommon;
                }
                textRootPath.Text = String.Join(Path.DirectorySeparatorChar.ToString(), commonPath.ToArray());
                btBrowse.Enabled  = commonPath.Count > 0;
            }
        }
        /// <summary>
        /// Check and refresh the view for each repo
        /// This method also enables the form's Close button if all repos are checked OK
        /// </summary>
        private void RefreshView()
        {
            list.Columns[1].Width = 75;
            bool enableClosing = true;

            foreach (ListViewItem item in list.Items)
            {
                ClassRepo repo = item.Tag as ClassRepo;
                item.Text = repo.Path;
                ClassUtils.DirStatType stat = ClassUtils.DirStat(repo.Path);
                switch (stat)
                {
                case ClassUtils.DirStatType.Invalid:
                    item.SubItems[1].Text      = "Non-existing";
                    enableClosing              = false;
                    item.SubItems[0].ForeColor = Color.Red;
                    break;

                case ClassUtils.DirStatType.Empty:
                    item.SubItems[1].Text = "Empty";
                    enableClosing         = false;
                    break;

                case ClassUtils.DirStatType.Git:
                    item.SubItems[1].Text      = "OK";
                    item.SubItems[0].ForeColor = Color.DarkOliveGreen;
                    break;

                case ClassUtils.DirStatType.Nongit:
                    item.SubItems[1].Text = "Non-empty";
                    enableClosing         = false;
                    break;
                }
            }
            btClose.Enabled = enableClosing;
        }
 /// <summary>
 /// Text in the local directory path changed. Validate the entry.
 /// </summary>
 private void TextBoxLocalTextChanged(object sender, EventArgs e)
 {
     btNext.Enabled = ClassUtils.DirStat(Local) == ClassUtils.DirStatType.Git;
 }
Exemple #4
0
        /// <summary>
        /// Load or merge a set of repositories from a file.
        /// Returns true is loading succeeded and this class is assigned a new set of repos.
        /// Returns false if loading failed, or was cancelled. The repos in this class did not change.
        /// If the requested operation is a merge, isImport=true, the new set of repos will be merged with the existing one.
        /// </summary>
        public bool Load(string fileName, bool isImport)
        {
            // Wrap the opening of a repository database with an outer handler
            try
            {
                using (FileStream file = new FileStream(fileName, FileMode.Open))
                {
                    try
                    {
                        // Load list of repos and the default repo string into temporary objects
                        BinaryFormatter  rd          = new BinaryFormatter();
                        List <ClassRepo> newRepos    = (List <ClassRepo>)rd.Deserialize(file);
                        string           defaultRepo = (string)rd.Deserialize(file);

                        // WAR: Mono 2.6.7 does not support serialization of a HashSet. At the same time...
                        // Quickly check that each repo is valid (find if at least one is not)
                        bool allOK = true;
                        foreach (ClassRepo repo in newRepos)
                        {
                            allOK &= ClassUtils.DirStat(repo.Path) == ClassUtils.DirStatType.Git;
                            repo.ExpansionReset(null);
                        }

                        // If at least one repo was not valid, give the user a chance to recreate it
                        if (allOK == false)
                        {
                            FormRecreateRepos recreateRepos = new FormRecreateRepos();
                            recreateRepos.Repos = newRepos;
                            // The "Accept" button in the recreate repos dialog will not be enabled
                            // until every repo has been configured properly. User can always cancel
                            // that process in which case we will not load the selected repo.
                            if (recreateRepos.ShowDialog() == DialogResult.Cancel)
                            {
                                return(false);
                            }
                            newRepos = recreateRepos.Repos;
                        }

                        // If the operation is a simple load, assign our object's list of repos
                        // Otherwise, we merge the new set with the existing one
                        if (isImport)
                        {
                            Repos.AddRange(newRepos);
                        }
                        // After we merge the new set of repos, current/default repo remains the same
                        else
                        {
                            Repos = newRepos;
                            // Upon load, set the current based on the default repo
                            Default = Repos.Find(r => r.Path == defaultRepo);
                            SetCurrent(Default);
                        }
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        throw new ClassException(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                App.PrintLogMessage(ex.Message, MessageType.Error);
            }
            return(false);
        }