示例#1
0
        private void PatchButton_Click(object sender, RoutedEventArgs e)
        {
            if (_differences is null)
            {
                return;
            }

            SecondFile.With(c =>
            {
                c.ReadOnlyMode = false;

                foreach (BlockListItem itm in FileDiffBlockList.Children)
                {
                    var diffList = _differences.Where(d => d.BytePositionInStream >= itm.CustomBlock.StartOffset &&
                                                      d.BytePositionInStream <= itm.CustomBlock.StopOffset);

                    foreach (ByteDifference byteDiff in diffList)
                    {
                        c.ModifyByte(byteDiff.Destination, byteDiff.BytePositionInStream);
                    }

                    itm.PatchBlockButton.IsEnabled = false;
                }

                c.ReadOnlyMode = true;
            });
        }
        private void PatchButton_Click(object sender, RoutedEventArgs e)
        {
            if (_differences is null)
            {
                return;
            }

            SecondFile.ReadOnlyMode = false;

            foreach (BlockListItem itm in FileDiffBlockList.Items)
            {
                var diffList = _differences.Where(c => c.BytePositionInStream >= itm.CustomBlock.StartOffset &&
                                                  c.BytePositionInStream <= itm.CustomBlock.StopOffset);

                foreach (ByteDifference byteDiff in diffList)
                {
                    SecondFile.AddByteModified(byteDiff.Destination, byteDiff.BytePositionInStream);
                }

                itm.PatchBlockButton.IsEnabled = false;
            }

            SecondFile.ReadOnlyMode = true;
            SecondFile.RefreshView();
        }
        /// <summary>
        /// Patch the selected block in the second file
        /// </summary>
        private void BlockItem_PatchButtonClick(object sender, EventArgs e)
        {
            if (sender is not BlockListItem itm)
            {
                return;
            }
            if (_differences is null)
            {
                return;
            }

            SecondFile.ReadOnlyMode = false;

            var diffList = _differences.Where(c => c.BytePositionInStream >= itm.CustomBlock.StartOffset &&
                                              c.BytePositionInStream <= itm.CustomBlock.StopOffset);

            foreach (ByteDifference byteDiff in diffList)
            {
                SecondFile.AddByteModified(byteDiff.Origine, byteDiff.BytePositionInStream);
            }

            SecondFile.ReadOnlyMode = true;
            SecondFile.RefreshView();

            itm.PatchBlockButton.IsEnabled = false;
        }
示例#4
0
        /// <summary>
        /// Update view when item is clicked
        /// </summary>
        private void BlockItem_Click(object sender, EventArgs e)
        {
            if (_internalChange)
            {
                return;
            }
            if (sender is not BlockListItem blockitm)
            {
                return;
            }
            if (_differences is null)
            {
                return;
            }

            //Clear UI
            FileDiffBytesList.Items.Clear();

            _internalChange = true;
            FirstFile.SetPosition(blockitm.CustomBlock.StartOffset, 1);
            SecondFile.SetPosition(blockitm.CustomBlock.StartOffset, 1);
            _internalChange = false;

            //Load list of byte difference
            foreach (ByteDifference byteDifference in _differences
                     .Where(c => c.BytePositionInStream >= blockitm.CustomBlock.StartOffset &&
                            c.BytePositionInStream <= blockitm.CustomBlock.StopOffset))
            {
                byteDifference.Color = blockitm.CustomBlock.Color;
                FileDiffBytesList.Items.Add(new ByteDifferenceListItem(byteDifference));
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            Console.WriteLine(" ~~~~~ Document Merger ~~~~~ ");
            Console.WriteLine();

            string FirstFile;
            string SecondFile;

            do
            { //ask user for file names & verifies if they exist
                Console.WriteLine("Name of first file: ");
                FirstFile = GetInput();
                Console.WriteLine("Name second file: ");
                SecondFile = GetInput();

                string NewFileName = FirstFile.Substring(0, 4) + SecondFile.Substring(0, 4) + ".txt"; //combines file names, removes .txt from first/second files and adds it to end of combined name
                string NewFileText = Reader(FirstFile) + Reader(SecondFile);                          // combines file text

                NewFile(NewFileText, NewFileName);

                //display that file was saved if no exception

                Console.WriteLine("{0} was successfully saved. The document contains {1} characters", NewFileName, NewFileText.Length);

                //ask if user wants to merge two more

                Console.WriteLine("Would you like to merge any more? (y/n): ");
            } while (Console.ReadLine().ToLower().Equals("y"));
        }
示例#6
0
        /// <summary>
        /// Find the difference of the two loaded file and add to lists the results
        /// </summary>
        private void FindDifference()
        {
            ClearUI();

            if (FirstFile.FileName == string.Empty || SecondFile.FileName == string.Empty)
            {
                return;
            }

            FileDiffBlockList.Children.Clear();

            //load the difference
            _differences = FirstFile.Compare(SecondFile).ToList();

            //Load list of difference
            var cbb = new CustomBackgroundBlock();
            int j   = 0;

            foreach (ByteDifference byteDifference in _differences)
            {
                //create or update custom background block
                if (j == 0)
                {
                    cbb = new CustomBackgroundBlock(byteDifference.BytePositionInStream, ++j, RandomBrushes.PickBrush());
                }
                else
                {
                    cbb.Length = ++j;
                }

                if (!_differences.Any(c => c.BytePositionInStream == byteDifference.BytePositionInStream + 1))
                {
                    j = 0;

                    new BlockListItem(cbb).With(c =>
                    {
                        c.PatchButtonClick += BlockItem_PatchButtonClick;
                        c.Click            += BlockItem_Click;
                        _blockListItem.Add(c);
                    });

                    //add to hexeditor
                    FirstFile.CustomBackgroundBlockItems.Add(cbb);
                    SecondFile.CustomBackgroundBlockItems.Add(cbb);
                }
            }

            //Update progressbar
            BlockItemProgress.Maximum = _blockListItem.Count();
            UpdateListofBlockItem();

            //refresh editor
            FirstFile.RefreshView();
            SecondFile.RefreshView();

            //Enable patch button
            PatchButton.IsEnabled = true;
        }
        private void FindDifference()
        {
            ClearUI();

            if (FirstFile.FileName == string.Empty || SecondFile.FileName == string.Empty)
            {
                return;
            }

            var cbb = new CustomBackgroundBlock();
            int j   = 0;

            _differences = FirstFile.Compare(SecondFile)
                           .ToList()
                           .OrderBy(c => c.BytePositionInStream);

            long previousPosition = _differences.First().BytePositionInStream;

            //Load list of difference

            ///////////// NOT COMPLETED... IS IN DEBUG....

            foreach (ByteDifference byteDifference in _differences)
            {
                if (j == 0)
                {
                    cbb = new CustomBackgroundBlock(byteDifference.BytePositionInStream, ++j, RandomBrushes.PickBrush());
                }
                else
                {
                    cbb.Length = ++j;
                }

                if (byteDifference.BytePositionInStream != previousPosition + 1)
                {
                    j = 0;

                    new BlockListItem(cbb).With(c =>
                    {
                        c.PatchButtonClick += BlockItem_PatchButtonClick;

                        FileDiffBlockList.Items.Add(c);
                    });

                    //add to hexeditor
                    FirstFile.CustomBackgroundBlockItems.Add(cbb);
                    SecondFile.CustomBackgroundBlockItems.Add(cbb);
                }

                previousPosition = byteDifference.BytePositionInStream;
            }

            //refresh editor
            FirstFile.RefreshView();
            SecondFile.RefreshView();
        }
 /// <summary>
 /// Clear the difference in various control
 /// </summary>
 private void ClearUI()
 {
     FileDiffBytesList.Items.Clear();
     FileDiffBlockList.Items.Clear();
     FirstFile.ClearCustomBackgroundBlock();
     SecondFile.ClearCustomBackgroundBlock();
     SecondFile.ClearAllChange();
     PatchButton.IsEnabled = false;
     _differences          = null;
 }
        private void FirstFile_VerticalScrollBarChanged(object sender, ByteEventArgs e)
        {
            if (_internalChange)
            {
                return;
            }

            _internalChange = true;
            SecondFile.SetPosition(e.BytePositionInStream);
            _internalChange = false;
        }
        private void SaveChangeButton_Click(object sender, RoutedEventArgs e)
        {
            SecondFile.With(c =>
            {
                c.ReadOnlyMode = false;
                c.SubmitChanges();
                c.ReadOnlyMode = true;
            });

            ClearUI();
        }
        private void InsertNewButton_Click(object sender, RoutedEventArgs e)
        {
            string name      = Convert.ToString(NameTextBox.Text);
            int    cellPhone = Convert.ToInt32(CellPhoneTextBox.Text);
            string resultName;
            string resultCellphone;

            SecondFile validations = new SecondFile();

            resultName         = validations.validarNome(name);
            resultCellphone    = validations.validarCelular(cellPhone);
            nameTextBlock.Text = string.Format("Nome: {0}", resultName);
            CellTextBox.Text   = string.Format("Celular: {0}", resultCellphone);
        }
示例#12
0
        /// <summary>
        /// NOT COMPLETED... bugged and need optimisation ;)
        /// </summary>
        private void FindDifference()
        {
            ClearUI();

            if (FirstFile.FileName == string.Empty || SecondFile.FileName == string.Empty)
            {
                return;
            }

            var cbb = new CustomBackgroundBlock();
            int j   = 0;

            _differences = FirstFile.Compare(SecondFile).ToList();

            //Load list of difference
            foreach (ByteDifference byteDifference in _differences.OrderBy(c => c.BytePositionInStream))
            {
                //create or update custom background block
                if (j == 0)
                {
                    cbb = new CustomBackgroundBlock(byteDifference.BytePositionInStream, ++j, RandomBrushes.PickBrush());
                }
                else
                {
                    cbb.Length = ++j;
                }


                if (_differences.Any(c => c.BytePositionInStream == byteDifference.BytePositionInStream + 1))
                {
                    j = 0;

                    new BlockListItem(cbb).With(c =>
                    {
                        c.PatchButtonClick += BlockItem_PatchButtonClick;

                        FileDiffBlockList.Items.Add(c);
                    });

                    //add to hexeditor
                    FirstFile.CustomBackgroundBlockItems.Add(cbb);
                    SecondFile.CustomBackgroundBlockItems.Add(cbb);
                }
            }

            //refresh editor
            FirstFile.RefreshView();
            SecondFile.RefreshView();
        }
        private void FileDiffBytesList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (_internalChange)
            {
                return;
            }
            if (FileDiffBytesList.SelectedItem is not ByteDifferenceListItem byteDifferenceItem)
            {
                return;
            }

            _internalChange = true;
            FirstFile.SetPosition(byteDifferenceItem.ByteDiff.BytePositionInStream, 1);
            SecondFile.SetPosition(byteDifferenceItem.ByteDiff.BytePositionInStream, 1);
            _internalChange = false;
        }
示例#14
0
        /// <summary>
        /// Синхронизация файлов в паре
        /// </summary>
        public void Sync()
        {
            if (!IsFirstFileSet)
            {
                throw new InvalidOperationException("Не установлен первый файл в синхропаре.");
            }
            if (!IsSecondFileSet)
            {
                throw new InvalidOperationException("Не установлен второй файл в синхропаре.");
            }

            // считываем актуальные метаданные файлов
            var meta1 = FirstFile.RetrieveFileMetadata();
            var meta2 = SecondFile.RetrieveFileMetadata();

            // по метаданным определяем файл который изменялся последним
            if (meta1.LastModified != meta2.LastModified)
            {
                if (meta1.LastModified > meta2.LastModified) // если последним изменяли первый файл:
                {
                    if (NeedBackup)
                    {
                        // синхронизируем файлы с бекапом
                        SyncTransactionWithBackup(_manager, SecondFile, FirstFile, BackupDirPath);
                    }
                    else
                    {
                        // синхронизируем файлы без бекапа
                        SyncTransaction(_manager, SecondFile, FirstFile);
                    }
                }
                else // если последним изменяли второй файл:
                {
                    if (NeedBackup)
                    {
                        // синхронизируем файлы с бекапом
                        SyncTransactionWithBackup(_manager, FirstFile, SecondFile, BackupDirPath);
                    }
                    else
                    {
                        // синхронизируем файлы без бекапа
                        SyncTransaction(_manager, FirstFile, SecondFile);
                    }
                }
            }
        }
        private void FileDiffBlockList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (_internalChange)
            {
                return;
            }
            if (FileDiffBlockList.SelectedItem is not BlockListItem blockitm)
            {
                return;
            }

            _internalChange = true;
            FirstFile.SetPosition(blockitm.CustomBlock.StartOffset, 1);
            SecondFile.SetPosition(blockitm.CustomBlock.StartOffset, 1);
            _internalChange = false;

            LoadByteDifferenceList();
        }