예제 #1
0
        private void PushPatch(DirectoryInfo patchCopyDir, List <FileInfoWithPatchOptions> patchFiles, bool isDMFR)
        {
            LogForm lf = new LogForm();

            VSSUtils.sender = lf.AddToLog;
            lf.Show();

            Thread th = new Thread(() =>
            {
                DisableVSSButtons();

                lf.AddToLog("Выкладывание патча");
                if (patchUtils.PushPatch(patchCopyDir, patchFiles, isDMFR))
                {
                    lf.AddToLog(Environment.NewLine + "Патч выложен!");
                    if (MessageBox.Show("Патч выложен!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        if (!lf.IsDisposed)
                        {
                            lf.Invoke(new Action(() => lf.Close()));
                        }
                    }
                }

                OSUtils.SetAttributesNormal(patchCopyDir);
                Directory.Delete(patchCopyDir.FullName, true);

                EnableVSSButtons();
            });

            th.Start();
        }
예제 #2
0
        private void PushPatchMain(bool isDMFR)
        {
            if (Directory.Exists(TbPatchLocation.Text))
            {
                DirectoryInfo patchDir     = new DirectoryInfo(TbPatchLocation.Text);
                DirectoryInfo patchCopyDir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, patchDir.Name));

                if (patchCopyDir.Exists)
                {
                    OSUtils.SetAttributesNormal(patchCopyDir);
                    Directory.Delete(patchCopyDir.FullName, true);
                }

                CopyDir(patchDir.FullName, patchCopyDir.FullName);
                OSUtils.SetAttributesNormal(patchCopyDir);

                List <FileInfoWithPatchOptions> patchFiles =
                    DgvFileList.Rows.Cast <DataGridViewRow>()
                    .Where(x => x.Cells[0].Value != null)
                    .Select(x => new FileInfoWithPatchOptions(
                                new FileInfo(
                                    Path.Combine(patchCopyDir.FullName, (string)x.Cells[0].Value)),
                                (bool)x.Cells[1].Value,
                                (bool)x.Cells[2].Value))
                    .ToList();

                PushPatch(patchCopyDir, patchFiles, isDMFR);
            }
            else
            {
                MessageBox.Show("Папка с патчем не найдена!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        public static bool CreateFPScenarioByFiles(DirectoryInfo patchDirectory)
        {
            SortedList <ScenarioKey, string> priorityLinePair = new SortedList <ScenarioKey, string>(new DuplicateKeyComparer <ScenarioKey>());

            string        startWFDir = Path.Combine(patchDirectory.FullName, "start_wf");
            DirectoryInfo dir        = new DirectoryInfo(startWFDir);

            if (Directory.Exists(startWFDir))
            {
                OSUtils.SetAttributesNormal(dir);
                OSUtils.DeleteDir(dir);
            }

            foreach (FileInfo fileInfo in patchDirectory.EnumerateFiles("*.xml", SearchOption.AllDirectories))
            {
                if (!fileInfo.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    if (fileInfo.Directory.Name.Equals(Properties.Settings.Default.STWFFolder, StringComparison.InvariantCultureIgnoreCase) ||
                        fileInfo.Directory.Parent != null && fileInfo.Directory.Parent.Name.Equals(Properties.Settings.Default.STWFFolder, StringComparison.InvariantCultureIgnoreCase) && fileInfo.Directory.Name.Equals("WORKFLOWS", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (Regex.IsMatch(fileInfo.Name, Properties.Settings.Default.CreateSTWFRegex))
                        {
                            Directory.CreateDirectory(startWFDir);

                            string wfName      = Path.GetFileNameWithoutExtension(fileInfo.FullName);
                            string startWFFile = Path.Combine(startWFDir, $"start_{wfName}.txt");
                            using (File.Create(startWFFile)) { }
                            using (StreamWriter tw = new StreamWriter(startWFFile, false, Encoding.GetEncoding("Windows-1251")))
                            {
                                tw.Write($" -f FLOW_CONTROL -wait {wfName}");
                            }
                        }
                    }
                }
            }

            foreach (FileInfo fileInfo in patchDirectory.EnumerateFiles("*.*", SearchOption.AllDirectories))
            {
                if (!fileInfo.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    string fromFPPath = fileInfo.FullName.Substring(patchDirectory.FullName.Length + 1);
                    if (!WrongFiles.IsMatch(fromFPPath))
                    {
                        if (CreateScenarioLineByFromFPDirPath(fromFPPath, out string scenarioLine))
                        {
                            priorityLinePair.Add(new ScenarioKey(Priority(scenarioLine), scenarioLine), scenarioLine);
                        }
                    }
                }
            }

            SaveFileSc(patchDirectory, priorityLinePair.Values);

            return(true);
        }
예제 #4
0
        private void DeleteLocalIfNotExistsInVSS(VSSItem remote, DirectoryInfo local)
        {
            foreach (var subFile in local.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
            {
                bool found = false;
                foreach (VSSItem subitem in remote.Items)
                {
                    //1 - файл
                    if (subitem.Type == 1 && subitem.Name.Equals(subFile.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    if (!subFile.Name.Equals("vssver2.scc", StringComparison.InvariantCultureIgnoreCase))
                    {
                        subFile.Delete();
                    }
                }
            }

            Dictionary <string, DirectoryInfo> notExistsInVSS = new Dictionary <string, DirectoryInfo>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var dir in local.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
            {
                notExistsInVSS.Add(dir.Name, dir);
            }

            foreach (VSSItem subitem in remote.Items)
            {
                notExistsInVSS.Remove(subitem.Name);
                //0 - папка
                if (subitem.Type == 0)
                {
                    DirectoryInfo subdestination = new DirectoryInfo(Path.Combine(local.FullName, subitem.Name));
                    DeleteLocalIfNotExistsInVSS(subitem, subdestination);
                }
            }

            foreach (var dir in notExistsInVSS.Values)
            {
                OSUtils.SetAttributesNormal(dir);
                Directory.Delete(dir.FullName, true);
            }
        }
예제 #5
0
        private void PushPatch(DirectoryInfo patchCopyDir, List <FileInfoWithPatchOptions> patchFiles)
        {
            LogForm lf = new LogForm();

            VSSUtils.sender = lf.AddToLog;
            lf.Show();

            lf.AddToLog("Проверка патча");
            Thread th = new Thread(() =>
            {
                DisableVSSButtons();

                if (CheckPatch(patchCopyDir, patchFiles))
                {
                    lf.AddToLog("Выкладывание патча");
                    if (patchUtils.PushPatch(patchCopyDir, patchFiles, out List <string> vssPathCheckedOutToAnotherUser))
                    {
                        lf.AddToLog(Environment.NewLine + "Патч выложен!");
                        if (MessageBox.Show("Патч выложен!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            if (!lf.IsDisposed)
                            {
                                lf.Invoke(new Action(() => lf.Close()));
                            }
                        }
                    }
                    else
                    {
                        EnterValueForm ef = new EnterValueForm("Файлы checked out другим пользователем. Невозможно добавить:", string.Join(Environment.NewLine, vssPathCheckedOutToAnotherUser));
                        ef.ShowDialog();
                    }
                }

                OSUtils.SetAttributesNormal(patchCopyDir);
                Directory.Delete(patchCopyDir.FullName, true);

                EnableVSSButtons();
            });

            th.Start();
        }
예제 #6
0
        private void BtTest_Click(object sender, EventArgs e)
        {
            VSSUtils vss = new VSSUtils(Properties.Settings.Default.BaseLocation, Environment.UserName);

            LogForm lf = new LogForm();

            VSSUtils.sender = lf.AddToLog;
            lf.Show();

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description  = "Необходимо выбрать папку для хранения патчей";
            fbd.SelectedPath = Properties.Settings.Default.PatchesLocalDir;

            DirectoryInfo localDir;

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                localDir = new DirectoryInfo(fbd.SelectedPath);
                Properties.Settings.Default.PatchesLocalDir = fbd.SelectedPath;
                Properties.Settings.Default.Save();

                TbErrors.Clear();

                th = new Thread(() =>
                {
                    BtStop.Invoke(new Action(() => BtStop.Enabled = true));
                    BtTest.Invoke(new Action(() => BtTest.Enabled = false));

                    foreach (string item in TbPatchList.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string dir = item.Split('/').Last();

                        DirectoryInfo patchDir = new DirectoryInfo(Path.Combine(localDir.FullName, dir));

                        if (Directory.Exists(patchDir.FullName))
                        {
                            OSUtils.SetAttributesNormal(patchDir);
                            Directory.Delete(patchDir.FullName, true);
                        }
                        else
                        {
                            Directory.CreateDirectory(patchDir.FullName);
                        }

                        vss.Pull(item, patchDir);
                        OSUtils.SetAttributesNormal(patchDir);

                        vss.TestPatchDir(item, out string errDesc, patchDir);
                        TbErrors.Invoke(new Action(() => TbErrors.AppendText(errDesc)));

                        using (var sw = File.AppendText("err_log.txt"))
                        {
                            sw.WriteLine(errDesc);
                        }

                        lf.AddToLog("Проверка завершена!");
                    }

                    BtStop.Invoke(new Action(() => BtStop.Enabled = false));
                    BtTest.Invoke(new Action(() => BtTest.Enabled = true));
                    MessageBox.Show("Проверка завершена", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                });
                th.Start();


                Properties.Settings.Default.PatchesToTest = TbPatchList.Text;
                Properties.Settings.Default.Save();
            }
        }