/// <summary> /// Exports and shows obtained track names. /// </summary> private void showSoundtrackNamesMenuItem_Click(object sender, RoutedEventArgs e) { try { //obtain track list var tracks = Soundtrack.GetTrackNames(); //export to file using (var tracklistFile = new StreamWriter(File.Open(Cache.OutputDirectory + "tracknames.csv", FileMode.Create))) { //write headers tracklistFile.WriteLine("File Id,Name"); foreach (var track in tracks) { tracklistFile.WriteLine($"{track.Key},\"{track.Value}\""); } } //show file Process.Start(Cache.OutputDirectory + "tracknames.csv"); } catch (Exception ex) { DisplayError(ex, "Could not create track list."); } }
private void showMissingSoundtrackNamesMenuItem_Click(object sender, RoutedEventArgs e) { if (!Directory.Exists(Cache.OutputDirectory + "soundtrack/")) { MessageBox.Show("Soundtrack directory hasn't been created yet."); return; } try { var soundtrackDir = Cache.OutputDirectory + "soundtrack/"; var tracks = Soundtrack.GetTrackNames(); var missingTracks = new Dictionary <int, string>(); foreach (var track in tracks) { if (!Directory.EnumerateFiles(soundtrackDir, track.Value + ".*").Any()) { missingTracks.Add(track.Key, track.Value); } } //export to file using ( var missingTracklistFile = new StreamWriter(File.Open(Cache.OutputDirectory + "missingtracknames.csv", FileMode.Create))) { //write headers missingTracklistFile.WriteLine("File Id,Name"); foreach (var track in missingTracks) { missingTracklistFile.WriteLine($"{track.Key},\"{track.Value}\""); } } //show file Process.Start(Cache.OutputDirectory + "missingtracknames.csv"); } catch (Exception ex) { DisplayError(ex, "Could not create missing track list."); } }
private void updateSoundtrackNamesMenuItem_Click(object sender, RoutedEventArgs e) { if (!Directory.Exists(Cache.OutputDirectory + "soundtrack/")) { MessageBox.Show("Soundtrack directory hasn't been created yet."); return; } try { var soundtrackDir = Cache.OutputDirectory + "soundtrack/"; var tracks = Soundtrack.GetTrackNames(); var namedTracks = 0; foreach (var trackPair in tracks) { var foundFiles = Directory.GetFiles(soundtrackDir, trackPair.Key + ".*"); if (foundFiles.Length > 0) { var extension = Path.GetExtension(foundFiles[0]); var destination = soundtrackDir + trackPair.Value + extension; //delete destination if it exists if (File.Exists(destination)) { File.Delete(destination); } File.Move(foundFiles[0], destination); namedTracks++; } } MessageBox.Show($"Named {namedTracks} tracks."); } catch (Exception ex) { DisplayError(ex, "Could not update all track names."); } }