public WesternClassicalAlbumSet(MusicDb db, MusicOptions musicOptions, IEnumerable <MusicFile> musicFiles, TaskItem taskItem) : base(db, musicOptions, MusicStyles.WesternClassical, musicFiles, taskItem) { this.ArtistName = OpusType == OpusType.Collection ? "Various Composers" : MusicOptions.ReplaceAlias(FirstFile.Musician); this.AlbumName = FirstFile.OpusName; this.YearNumber = FirstFile.GetYear() ?? 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)); } }
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")); }
/// <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 SecondFile_VerticalScrollBarChanged(object sender, ByteEventArgs e) { if (_internalChange) { return; } _internalChange = true; FirstFile.SetPosition(e.BytePositionInStream); _internalChange = false; }
internal PopularMusicAlbumSet(MusicDb db, MusicOptions musicOptions, string artistName, string albumName, IEnumerable <MusicFile> musicFiles, TaskItem taskItem) : base(db, musicOptions, MusicStyles.Popular, musicFiles, taskItem) { this.ArtistName = FirstFile.GetArtistName() ?? artistName; this.AlbumName = FirstFile.GetWorkName() ?? albumName; this.YearNumber = FirstFile.GetYear() ?? 0; if (string.Compare(this.AlbumName, "Greatest Hits", true) == 0) { // prefix with artist name as there are so many called "Greatest Hits" this.AlbumName = $"{ArtistName} Greatest Hits"; } }
/// <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; }
/// <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 Performance GetPerformance(Composition composition, string orchestras, string conductors, string performers) { Debug.Assert(MusicDb != null); var performance = composition.Performances.SingleOrDefault(p => p.Orchestras.IsEqualIgnoreAccentsAndCase(orchestras) && p.Conductors.IsEqualIgnoreAccentsAndCase(conductors) && p.Performers.IsEqualIgnoreAccentsAndCase(performers)); if (performance != null) { // find a unique name for this performance var index = 1; var found = false; while (!found) { var name = $"{performers} ({++index})"; performance = composition.Performances.SingleOrDefault(p => p.Performers.IsEqualIgnoreAccentsAndCase(name)); found = performance == null; } } performance = new Performance { Composition = composition, Orchestras = orchestras, Conductors = conductors, Performers = performers, AlphamericPerformers = performers.ToAlphaNumerics(), Year = FirstFile.GetYear() ?? 0 }; var movementNumber = 0; foreach (var track in MusicFiles.Select(mf => mf.Track).OrderBy(x => x.Number)) { if (track == null || track.Performance != null) { Debugger.Break(); } track.MovementNumber = ++movementNumber; performance.Movements.Add(track); } Debug.Assert(performance.Movements.Count > 0); composition.Performances.Add(performance); return(performance); }
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(); }