コード例 #1
0
        public void Init(EnvironmentVariableTarget ev)
        {
            // MessageBox.Show("init");
            //  CurrentPathText = GetCurrentPathText();

            if (CurrentPathText != string.Empty)
            {
                CurrentPathLength = CurrentPathText.Length;

                CurrentPathList.Clear();
                CurrentPathList = GetCurrentPathList();

                CurrentPathCount = CurrentPathList.Count;

                // MessageBox.Show(PathSummary);
                Over1023         = CurrentPathLength > 1023;
                PathSummaryColor = Over1023 ? Color.Red : Color.Black;

                PathUnique = CurrentPathList.Where(Directory.Exists) // remove not exist
                             .Distinct().ToList();                   //remove duplicated

                DublicatedList.Clear();
                DublicatedList = GetDuplicatedList(CurrentPathList);

                NotExistList = new BindingList <string>(CurrentPathList.Where(item => !Directory.Exists(item)).ToList());
                PathSummary  = string.Format("Path Length: {0}, Count: {1}", CurrentPathLength, CurrentPathCount);
                if (Over1023)
                {
                    PathSummary += " (Over 1023 char)";
                }
                CanRepair    = GetRepairStatus();
                IsDuplicated = DublicatedList.Count > 0;
                PathChanged.Raise(this, null);
            }
        }
コード例 #2
0
        public Boolean RepairPath() //(List< string > newlist)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                List <string> Newlist = new List <string>();
                string        msg     = "Are you sure to repair the window path" + Environment.NewLine;
                msg += "The current path will be exported to external file";

                var result = MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result == DialogResult.Cancel)
                {
                    return(false);
                }



                Newlist = PathUnique.ToList();

                int size1 = Newlist.Sum(item => item.Length + 1);

                //bool shouldSave = size1 != CurrentPathText.Length;
                string s = "";

                Console.WriteLine("Excluding dublicated entries");

                Console.WriteLine("{0}: excluding dublicated entries", size1);


                //shoorten the path starting with last entries
                if (size1 > 1023)
                {
                    //int size2 = 0;
                    //  for (int index = 0; index < newlist.Count; index++)
                    for (int index = Newlist.Count - 1; index > 0; index--)
                    {
                        var item = Newlist[index];
                        Newlist[index] = FileSystemHelper.GetShortPathName(item);
                        size1          = Newlist.Sum(item2 => item2.Length + 1);
                        Console.WriteLine("short: {0}, newsize: {1}", size1, Newlist[index]);
                        if (size1 < 1023)
                        {
                            break;               //1023- 10 extra room for any next installation
                        }
                    } //for
                } //if

                string newPath = Newlist.Aggregate((workingSentence, next) => workingSentence + ";" + next);
                Console.WriteLine("final path new length {0} ", newPath.Length);
                Console.WriteLine(newPath);

                msg  = "The new path is " + Convert.ToString(size1) + Environment.NewLine;
                msg += "Are you sure to write the new path";

                result = MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result == DialogResult.Cancel)
                {
                    return(false);
                }

                //export to file
                BackupPath();
                SaveProgramPath(newPath);
                Refresh();
                _logger.Info("Repairing Path");
                PathChanged.Raise(this, null);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                _logger.Error("Error in Repair: " + ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show("Repair Completed Sucessfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
            return(false);
        }
コード例 #3
0
 public void Load()
 {
     CurrentPathText = GetCurrentPathText();
     Init();
     PathChanged.Raise(this, null);
 }