예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }