//--------------- // External Apps //--------------- private string callXmaParse( string workingFolder, string workingFile, XmaConverterStruct taskStruct, out string consoleOutput, out string consoleError) { string xmaParseWorkingPath; string xmaParseOutputFilePath; Process xmaParseProcess; StringBuilder parameters = new StringBuilder(); // copy to working folder xmaParseWorkingPath = Path.Combine(workingFolder, Path.GetFileName(XMAPARSE_FULL_PATH)); File.Copy(XMAPARSE_FULL_PATH, xmaParseWorkingPath, true); // build parameters parameters.AppendFormat(" \"{0}\"", Path.GetFileName(workingFile)); // Filename parameters.AppendFormat(" -{0}", taskStruct.XmaParseXmaType); // Input File Type using (FileStream workingFileStream = File.OpenRead(workingFile)) { // offset if (taskStruct.StartOffsetAfterRiffHeader) { uint riffHeaderSize = RiffUtil.GetRiffHeaderSize(workingFile); parameters.AppendFormat(" -o {0}", riffHeaderSize.ToString("X")); } else if ((taskStruct.XmaParseStartOffsetIsStatic) && (!String.IsNullOrEmpty(taskStruct.XmaParseStartOffset))) { // allow decimal or hex input, convert to hex for xma_parse.exe parameters.AppendFormat(" -o {0}", ByteConversion.GetLongValueFromString(taskStruct.XmaParseStartOffset).ToString("X")); } else if (!String.IsNullOrEmpty(taskStruct.XmaParseStartOffsetOffsetInfo.OffsetValue)) { long offsetValue = ParseFile.GetVaryingByteValueAtAbsoluteOffset(workingFileStream, taskStruct.XmaParseStartOffsetOffsetInfo, true); parameters.AppendFormat(" -o {0}", offsetValue.ToString("X")); } // block size if ((taskStruct.XmaParseBlockSizeIsStatic) && (!String.IsNullOrEmpty(taskStruct.XmaParseBlockSize))) { // allow decimal or hex input, convert to hex for xma_parse.exe parameters.AppendFormat(" -b {0}", ByteConversion.GetLongValueFromString(taskStruct.XmaParseBlockSize).ToString("X")); } else if (!String.IsNullOrEmpty(taskStruct.XmaParseBlockSizeOffsetInfo.OffsetValue)) { long blockSizeValue = ParseFile.GetVaryingByteValueAtAbsoluteOffset(workingFileStream, taskStruct.XmaParseBlockSizeOffsetInfo, true); parameters.AppendFormat(" -b {0}", blockSizeValue.ToString("X")); } // data size if (taskStruct.GetDataSizeFromRiffHeader) { uint riffDataSize = RiffUtil.GetDataSizeFromRiffHeader(workingFile); parameters.AppendFormat(" -d {0}", riffDataSize.ToString("X")); } else if ((taskStruct.XmaParseDataSizeIsStatic) && (!String.IsNullOrEmpty(taskStruct.XmaParseDataSize))) { // allow decimal or hex input, convert to hex for xma_parse.exe parameters.AppendFormat(" -d {0}", ByteConversion.GetLongValueFromString(taskStruct.XmaParseDataSize).ToString("X")); } else if (!String.IsNullOrEmpty(taskStruct.XmaParseDataSizeOffsetInfo.OffsetValue)) { long dataSizeValue = ParseFile.GetVaryingByteValueAtAbsoluteOffset(workingFileStream, taskStruct.XmaParseDataSizeOffsetInfo, true); parameters.AppendFormat(" -d {0}", dataSizeValue.ToString("X")); } } // output name xmaParseOutputFilePath = String.Format("{0}{1}", Path.GetFileNameWithoutExtension(workingFile), XMAPARSE_OUTPUT_EXTENSION); if (taskStruct.XmaParseDoRebuildMode) { parameters.AppendFormat(" -r \"{0}\"", xmaParseOutputFilePath); } else { parameters.AppendFormat(" -x \"{0}\"", xmaParseOutputFilePath); } // call function xmaParseProcess = new Process(); xmaParseProcess.StartInfo = new ProcessStartInfo(xmaParseWorkingPath); xmaParseProcess.StartInfo.WorkingDirectory = workingFolder; xmaParseProcess.StartInfo.Arguments = parameters.ToString(); xmaParseProcess.StartInfo.UseShellExecute = false; xmaParseProcess.StartInfo.CreateNoWindow = true; xmaParseProcess.StartInfo.RedirectStandardError = true; xmaParseProcess.StartInfo.RedirectStandardOutput = true; bool isSuccess = xmaParseProcess.Start(); consoleOutput = xmaParseProcess.StandardOutput.ReadToEnd(); consoleError = xmaParseProcess.StandardError.ReadToEnd(); xmaParseProcess.WaitForExit(); xmaParseProcess.Close(); xmaParseProcess.Dispose(); xmaParseOutputFilePath = xmaParseWorkingPath = Path.Combine(workingFolder, xmaParseOutputFilePath); return(xmaParseOutputFilePath); }
protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pXmaConverterStruct, DoWorkEventArgs e) { XmaConverterStruct taskStruct = (XmaConverterStruct)pXmaConverterStruct; string workingFolder; string workingFile; string workingSourceFile; string consoleOutput = String.Empty; string consoleError = String.Empty; uint riffFrequency; uint riffChannelCount; uint riffFileSize; string riffHeaderedFile; byte[] riffHeaderBytes; uint loopStart; uint loopLength; uint loopEnd; byte[] posBytes; //------------------ // output file name //------------------ this.ShowOutput(pPath, String.Format("[{0}]", Path.GetFileName(pPath)), false); //---------------------- // build working folder //---------------------- workingFolder = this.createWorkingFolder(pPath, taskStruct); //------------------------------------ // copy source file to working folder //------------------------------------ workingSourceFile = Path.Combine(workingFolder, Path.GetFileName(pPath)); File.Copy(pPath, workingSourceFile, true); taskStruct.NumberOfStreams = 1; for (int i = 0; i < taskStruct.NumberOfStreams; i++) { // set working file workingFile = workingSourceFile; #region XMAPARSE //--------------------------- // xma_parse.exe //--------------------------- if (taskStruct.DoXmaParse) { this.ShowOutput(pPath, "---- calling xma_parse.exe", false); // call xma_parse and set output as working_file for next step workingFile = this.callXmaParse(workingFolder, workingFile, taskStruct, out consoleOutput, out consoleError); // show output if (taskStruct.ShowExeOutput && !String.IsNullOrEmpty(consoleOutput)) { this.ShowOutput(pPath, consoleOutput, false); } // clear errors if ignore is selected, but only if a file was created if (taskStruct.XmaParseIgnoreErrors && (File.Exists(workingFile))) { consoleError = String.Empty; } } // #endregion #region RIFF HEADER if ((taskStruct.DoRiffHeader) && (String.IsNullOrEmpty(consoleError))) { //----------------- // get RIFF header //----------------- this.ShowOutput(pPath, "---- adding RIFF header.", false); // frequency if (taskStruct.GetFrequencyFromRiffHeader) { riffFrequency = (uint)RiffUtil.GetFrequencyFromRiffHeader(workingSourceFile); } else if (taskStruct.GetFrequencyFromOffset) { using (FileStream fs = File.OpenRead(workingSourceFile)) { riffFrequency = (uint)ParseFile.GetVaryingByteValueAtAbsoluteOffset(fs, taskStruct.RiffHeaderFrequencyOffsetInfo, true); } } else { riffFrequency = (uint)ByteConversion.GetLongValueFromString(taskStruct.RiffFrequency); } // channels if (taskStruct.GetChannelsFromRiffHeader) { riffChannelCount = RiffUtil.GetChannelsFromRiffHeader(workingSourceFile); } else if (taskStruct.GetChannelsFromOffset) { using (FileStream fs = File.OpenRead(workingSourceFile)) { riffChannelCount = (uint)ParseFile.GetVaryingByteValueAtAbsoluteOffset(fs, taskStruct.RiffHeaderChannelOffsetInfo, true); if (riffChannelCount > 2) { riffChannelCount = 2; } } } else { riffChannelCount = (uint)ByteConversion.GetLongValueFromString(taskStruct.RiffChannelCount); } riffFileSize = (uint)new FileInfo(workingFile).Length; riffHeaderBytes = this.getRiffHeader(riffFrequency, riffChannelCount, riffFileSize); //------------------------- // add RIFF header to file //------------------------- riffHeaderedFile = Path.ChangeExtension(workingFile, RIFF_COPY_OUTPUT_EXTENSION); FileUtil.AddHeaderToFile(riffHeaderBytes, workingFile, riffHeaderedFile); // set working file for next workingFile = riffHeaderedFile; } else if (!String.IsNullOrEmpty(consoleError)) { // dispay xma_parse.exe error this.ShowOutput(pPath, consoleError, true); } #endregion #region POS CREATOR //----------- // POS Maker //----------- if ((taskStruct.DoPosMaker) && (String.IsNullOrEmpty(consoleError))) { this.ShowOutput(pPath, "---- creating POS file", false); // loop start if (taskStruct.PosLoopStartIsStatic) { loopStart = (uint)ByteConversion.GetLongValueFromString(taskStruct.PosLoopStartStaticValue); } else { using (FileStream fs = File.OpenRead(workingSourceFile)) { loopStart = (uint)ParseFile.GetVaryingByteValueAtAbsoluteOffset(fs, taskStruct.PosLoopStartOffsetInfo, true); if (!String.IsNullOrEmpty(taskStruct.PosLoopStartOffsetInfo.CalculationString)) { string calculationString = taskStruct.PosLoopStartOffsetInfo.CalculationString.Replace(CalculatingOffsetDescription.OFFSET_VARIABLE_STRING, loopStart.ToString()); loopStart = (uint)ByteConversion.GetLongValueFromString(MathUtil.Evaluate(calculationString)); } } } // loop length if (taskStruct.PosLoopEndIsStatic) { loopLength = (uint)ByteConversion.GetLongValueFromString(taskStruct.PosLoopEndStaticValue); } else { using (FileStream fs = File.OpenRead(workingSourceFile)) { loopLength = (uint)ParseFile.GetVaryingByteValueAtAbsoluteOffset(fs, taskStruct.PosLoopEndOffsetInfo, true); if (!String.IsNullOrEmpty(taskStruct.PosLoopEndOffsetInfo.CalculationString)) { string calculationString = taskStruct.PosLoopEndOffsetInfo.CalculationString.Replace(CalculatingOffsetDescription.OFFSET_VARIABLE_STRING, loopLength.ToString()); loopLength = (uint)ByteConversion.GetLongValueFromString(MathUtil.Evaluate(calculationString)); } } } if (loopLength > 0) { loopEnd = loopStart + loopLength; // build .pos array and write to file posBytes = new byte[8]; Array.Copy(BitConverter.GetBytes(loopStart), 0, posBytes, 0, 4); Array.Copy(BitConverter.GetBytes(loopEnd), 0, posBytes, 4, 4); using (FileStream fs = File.Open(Path.ChangeExtension(workingSourceFile, ".pos"), FileMode.Create, FileAccess.Write)) { fs.Write(posBytes, 0, posBytes.Length); } } } #endregion #region TOWAV //----------- // ToWav.exe //----------- if ((taskStruct.DoToWav) && (String.IsNullOrEmpty(consoleError))) { this.ShowOutput(pPath, "---- calling ToWav.exe", false); // call ToWav.exe and set working file for next step (if ever needed) workingFile = this.callToWav(workingFolder, workingFile, taskStruct, out consoleOutput, out consoleError); // show output if (taskStruct.ShowExeOutput && !String.IsNullOrEmpty(consoleOutput)) { this.ShowOutput(pPath, consoleOutput, false); } // dispay ToWav.exe error if (!String.IsNullOrEmpty(consoleError)) { this.ShowOutput(pPath, consoleError, true); } } #endregion #region XMAENCODE //--------------- // XmaEncode.exe //--------------- else if ((taskStruct.DoXmaEncode) && (String.IsNullOrEmpty(consoleError))) { this.ShowOutput(pPath, "---- calling xmaencode.exe", false); // call xmaencode.exe and set working file for next step (if ever needed) workingFile = this.callXmaEncode(workingFolder, workingFile, taskStruct, out consoleOutput, out consoleError); // show output if (taskStruct.ShowExeOutput && !String.IsNullOrEmpty(consoleOutput)) { this.ShowOutput(pPath, consoleOutput, false); } // dispay xmaencode.exe error if (!String.IsNullOrEmpty(consoleError)) { this.ShowOutput(pPath, consoleError, true); } } #endregion } // for (int i = 0; i < taskStruct.NumberOfStreams; i++) //---------------------- // clean working folder //---------------------- this.cleanWorkingFolder(pPath, workingSourceFile, taskStruct); }