public void SerializeToDisk(string targetFile) { var yamlSerialzer = new SharpYaml.Serialization.Serializer(); var serializedData = yamlSerialzer.Serialize(this); string targetPath = Path.Combine(targetFile, GenerateCPKID() + ".yaml"); DirectoryGuard.CheckDirectory(targetPath); FileStream fs = new FileStream(targetPath, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(serializedData); sw.Close(); fs.Close(); }
public void WriteCSVFile(string fileName, List <IInstruction> fileContents, StringCollection fileStrings) { fileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".csv"); DirectoryGuard.CheckDirectory(fileName); FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); var csv = new CsvHelper.CsvWriter(sw); csv.Configuration.RegisterClassMap <CSVRecordMap>(); csv.WriteHeader <CSVRecord>(); csv.NextRecord(); string lastSpeaker = ""; foreach (var instruction in fileContents) { if (instruction is IHasStrings) { var temp = instruction as IHasStrings; List <CSVRecord> csvRecords = temp.GetCSVRecords(); foreach (var record in csvRecords) { record.originalText = fileStrings.GetString(record.stringID); if (record.speaker != lastSpeaker) { lastSpeaker = record.speaker; } else { record.speaker = ""; // blank out the name of the speaker if it is being repeated to make it easier to note when speaker changes and avoid massive walls of speakers text } csv.WriteRecord(record); csv.NextRecord(); } } } csv.Flush(); sw.Close(); fs.Close(); }
public MainWindow() { InitializeComponent(); CreateConnection(); DirectoryGuard.DirectoriesSanityCheck(); InitializeChatView(); InitializeStatistics(); _glowFadeOutAnimation = new ColorAnimation(Colors.WindowActiveGlow, Colors.WindowInactiveGlow, new Duration(new TimeSpan(0, 0, 0, 0, 150))); _glowFadeInAnimation = new ColorAnimation(Colors.WindowInactiveGlow, Colors.WindowActiveGlow, new Duration(new TimeSpan(0, 0, 0, 0, 150))); var borderActivateAnimation = new ColorAnimation(Colors.WindowInactiveBorder, Colors.WindowActiveBorder, new Duration(new TimeSpan(0, 0, 0, 0, 150))); var borderDeactivateAnimation = new ColorAnimation(Colors.WindowActiveBorder, Colors.WindowInactiveBorder, new Duration(new TimeSpan(0, 0, 0, 0, 150))); _borderActivateStoryboard = new Storyboard(); _borderDeactivateStoryboard = new Storyboard(); Storyboard.SetTarget(borderActivateAnimation, WindowBorder); Storyboard.SetTargetProperty(borderActivateAnimation, new PropertyPath("(Border.BorderBrush).(SolidColorBrush.Color)")); _borderActivateStoryboard.Children.Add(borderActivateAnimation); Storyboard.SetTarget(borderDeactivateAnimation, WindowBorder); Storyboard.SetTargetProperty(borderDeactivateAnimation, new PropertyPath("(Border.BorderBrush).(SolidColorBrush.Color)")); _borderDeactivateStoryboard.Children.Add(borderDeactivateAnimation); SettingsSelector.SettingsChanged += SettingsSelector_SettingsChanged; _debuggingWindow = new DebugWindow(App.Connection); _settingsWindow = new SettingsWindow(); _aboutWindow = new AboutWindow(); _archiveWindow = new ArchiveWindow(); _escTimer = new Timer(800); _escTimer.Elapsed += escTimer_Elapsed; SettingsSelector.SetConfigurationValue("Voivodeship", SettingsSelector.GetConfigurationValue <string>("Voivodeship")); }
protected override void OnStartup(StartupEventArgs e) { var systemVersion = Environment.OSVersion.Version; if (systemVersion.Major < 6) { MessageBox.Show("Incompatible system version, must be at least Windows Vista", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } DirectoryGuard.DirectoriesSanityCheck(); if (!HasWriteAccessToFolder(AppDomain.CurrentDomain.BaseDirectory)) { AlertWindow.Show(LocaleSelector.GetLocaleString("AlertWindow_NoWriteAccess")); CanWriteToCurrentFolder = false; } else { CanWriteToCurrentFolder = true; } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; WindowFlashHelper = new WindowFlashHelper(this); Connection = new Connection { SendUserAgent = SettingsSelector.GetConfigurationValue <bool>("Behavior_SendUserAgent") }; StatsManager = new StatsManager(Connection); ArchiveManager = new ArchiveManager(); LocaleSelector.SetLocaleIdentifier( SettingsSelector.GetConfigurationValue <string>("Language") ); ColorSchemeLoader = new ColorSchemeLoader(); ColorSchemeLoader.LoadColorSchemes(); ColorSchemeLoader.ApplyColors(); base.OnStartup(e); }
public bool BuildCPK(string buildFile) { if (!DeserializeFromDisk(buildFile)) { return(false); } List <CPKEmbeddedFileMeta> changedFiles = new List <CPKEmbeddedFileMeta>(); foreach (var file in files.Values) { string filePath = Path.Combine(ProjectFolder.GetRootDir(), file.filePath); if (!File.Exists(filePath)) { string errorMessage = string.Format("File {0} did not exist.", filePath); MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } FileStream fs = new FileStream(filePath, FileMode.Open); BinaryReader br = new BinaryReader(fs); byte[] fileAsBytes = br.ReadBytes((int)br.BaseStream.Length); br.Close(); fs.Close(); string checksum = Checksums.GetMD5(fileAsBytes); if (checksum != file.checksumValue) // file has been changed { changedFiles.Add(file); } } string originalCPKPath = Path.Combine(ProjectFolder.GetRootDir(), originalFileLocation); string targetCPKPath = Path.Combine(ProjectFolder.GetRootDir(), targetFileLocation); if (DebugSettings.REFRESH_REPACKED_FILES_ON_BUILD) { if (File.Exists(targetCPKPath)) // refresh files in repacked files folder just in case since 1) we will be using the repacked folder as our base to merge new changes into 2) a rebuild implies a refresh. perhaps some distinction between "build" and "clean build" would be a good idea later, which case it will most likely derive from this. { File.Delete(targetCPKPath); } else { DirectoryGuard.CheckDirectory(targetCPKPath); } File.Copy(originalCPKPath, targetCPKPath); } if (changedFiles.Count > 0) { var batchReplaceArg = new Dictionary <string, string>(); foreach (var file in changedFiles) { string fileName = file.fileName; if (!fileName.Contains("/")) // done to match the format used by the batch replacer { fileName = "/" + fileName; } batchReplaceArg[fileName] = Path.Combine(ProjectFolder.GetRootDir(), file.filePath); } ReplaceCPKFiles(originalCPKPath, targetCPKPath, batchReplaceArg); } return(true); }