public static bool checkIfTextIsParsableAsLong(string textToCheck, string labelValue) { bool isParsableNumber = true; if (!String.IsNullOrEmpty(textToCheck)) { try { long tempValue = ByteConversion.GetLongValueFromString(textToCheck); } catch (Exception) { MessageBox.Show(String.Format("Cannot convert \"{0}\" to a number: <{1}>", labelValue, textToCheck), "Conversion Error."); isParsableNumber = false; } } return(isParsableNumber); }
private void grpSourceFiles_DragDrop(object sender, DragEventArgs e) { if (this.validateEnteredData()) { string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false); ExtractSonyAdpcmWorker.ExtractSonyAdpcmStruct bwStruct = new ExtractSonyAdpcmWorker.ExtractSonyAdpcmStruct(); bwStruct.SourcePaths = s; bwStruct.OutputBatchFiles = this.cbOutputBatchScripts.Checked; if (!String.IsNullOrEmpty(this.tbStartOffset.Text)) { bwStruct.StartOffset = ByteConversion.GetLongValueFromString(this.tbStartOffset.Text); } else { bwStruct.StartOffset = 0; } base.backgroundWorker_Execute(bwStruct); } }
private int getIndexForSplitAudioTrackFileName(string splitAudioFileName) { int index = -1; string audioTrackIdString; int fileExtensionLocation; uint audioTrackId; // get track ID fileExtensionLocation = splitAudioFileName.IndexOf(BinkStream.DefaultFileExtensionAudioSplit, 0); audioTrackIdString = splitAudioFileName.Substring(fileExtensionLocation - 8, 8); audioTrackId = (uint)ByteConversion.GetLongValueFromString("0x" + audioTrackIdString); for (int i = 0; i < this.AudioTrackIds.Length; i++) { if (this.AudioTrackIds[i] == audioTrackId) { index = i; break; } } return(index); }
protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pInternalNameFileRenamerWorkerStruct, DoWorkEventArgs e) { InternalNameFileRenamerWorkerStruct taskStruct = (InternalNameFileRenamerWorkerStruct)pInternalNameFileRenamerWorkerStruct; byte[] terminatorBytes = null; int nameLength = 0; if (taskStruct.TerminatorBytes != null) { terminatorBytes = ByteConversion.GetBytesFromHexString(taskStruct.TerminatorBytes); } if (!String.IsNullOrEmpty(taskStruct.NameLength)) { nameLength = (int)ByteConversion.GetLongValueFromString(taskStruct.NameLength); } FileUtil.RenameFileUsingInternalName(pPath, ByteConversion.GetLongValueFromString(taskStruct.Offset), nameLength, terminatorBytes, taskStruct.MaintainOriginalExtension); }
private void RenameFilesFromExternalList(ExternalListFileRenamerStruct inputValues) { string fileMask = null; string[] sourceFiles; int sourceFileCount; long listFileLength; long fileNameOffset; StringBuilder renameScript; StringBuilder undoScript; string sourceFile; byte[] destinationFileTerminator = new byte[0]; long destinationFileBytesSize = -1; byte[] destinationFileBytes; string destinationFile; string destinationFolder; long currentOffset; // verify directory exists and list file exists if (Directory.Exists(inputValues.SourceFolder) && File.Exists(inputValues.ListFileLocation)) { // set file mask fileMask = inputValues.SourceFileMask.Trim(); fileMask = String.IsNullOrEmpty(fileMask) ? "*.*" : fileMask; // get source file count sourceFiles = Directory.GetFiles(inputValues.SourceFolder, fileMask, SearchOption.TopDirectoryOnly); sourceFileCount = sourceFiles.GetLength(0); // verify some source files exist if (sourceFileCount == 0) { throw new Exception(String.Format("Source directory is empty.")); } else { // convert file name offset to long fileNameOffset = ByteConversion.GetLongValueFromString(inputValues.OffsetToFileNames); // open List File using (FileStream listFs = File.Open(inputValues.ListFileLocation, FileMode.Open, FileAccess.Read, FileShare.Read)) { listFileLength = listFs.Length; // verify offset exists within list file if (listFileLength < fileNameOffset) { throw new IOException(String.Format("File name offset is greater than the size of the list file.")); } else { renameScript = new StringBuilder(); undoScript = new StringBuilder(); // parse file name terminator, if included if (inputValues.FileNameHasTerminator) { try { destinationFileTerminator = ByteConversion.GetBytesFromHexString(inputValues.FileNameTerminator); } catch (Exception ex1) { throw new FormatException(String.Format("Unable to convert File Name Terminator Bytes to hex: '{0}'", ex1.Message), ex1); } } else // convert static filename size { try { destinationFileBytesSize = ByteConversion.GetLongValueFromString(inputValues.FileNameStaticSize); } catch (Exception ex2) { throw new FormatException(String.Format("Unable to convert File Name static size fo a number: '{0}'", ex2.Message), ex2); } } try { // rename files currentOffset = fileNameOffset; for (int i = 0; i < sourceFileCount; i++) { sourceFile = sourceFiles[i]; // get name for files with a terminator if (inputValues.FileNameHasTerminator) { destinationFileBytesSize = ParseFile.GetNextOffset(listFs, currentOffset, destinationFileTerminator) - currentOffset; } // read destination file name if (destinationFileBytesSize > 0) { destinationFileBytes = ParseFile.ParseSimpleOffset(listFs, currentOffset, (int)destinationFileBytesSize); destinationFile = this.getFileNameFromEncodedBytes(inputValues.FileNameEncoding, inputValues.FileNameCodePage, destinationFileBytes); currentOffset += destinationFileBytesSize + destinationFileTerminator.Length; } else { this.progressStruct.Clear(); this.progressStruct.FileName = sourceFile; this.progressStruct.GenericMessage = String.Format("Warning: End of List File reached when renaming <{0}>{1}", sourceFile, Environment.NewLine); this.ReportProgress(Constants.ProgressMessageOnly, progressStruct); break; } // rename file and build scripts destinationFile = Path.Combine(inputValues.SourceFolder, destinationFile).Trim(); if (inputValues.KeepOriginalFileExtension) { if (String.IsNullOrEmpty(Path.GetExtension(destinationFile))) { destinationFile += Path.GetExtension(sourceFile); } else { Path.ChangeExtension(destinationFile, Path.GetExtension(sourceFile)); } } if (sourceFile != destinationFile) { renameScript.AppendFormat("rename \"{0}\" \"{1}\" {2}", Path.GetFileName(sourceFile), Path.GetFileName(destinationFile), Environment.NewLine); undoScript.AppendFormat("rename \"{0}\" \"{1}\" {2}", Path.GetFileName(destinationFile), Path.GetFileName(sourceFile), Environment.NewLine); destinationFolder = Path.GetDirectoryName(destinationFile); if (!Directory.Exists(destinationFolder)) { Directory.CreateDirectory(destinationFolder); } File.Move(sourceFile, destinationFile); } // report progress this.progressStruct.Clear(); this.progressStruct.FileName = sourceFile; this.ReportProgress(((i + 1) * 100) / sourceFileCount, progressStruct); } } finally { if (renameScript.Length > 0) { // write to file. FileUtil.CreateFileFromString(Path.Combine(inputValues.SourceFolder, RENAME_SCRIPT_NAME), renameScript.ToString()); } if (undoScript.Length > 0) { // write to file. FileUtil.CreateFileFromString(Path.Combine(inputValues.SourceFolder, UNDO_RENAME_SCRIPT_NAME), undoScript.ToString()); } } } // if (listFileLength < fileNameOffset) } // using (FileStream listFs = File.Open(inputValues.ListFileLocation, FileMode.Open, FileAccess.Read, FileShare.Read)) } // if (sourceFileCount == 0) } else { throw new IOException(String.Format("Directory not found: <{0}>", inputValues.SourceFolder)); } // if (Directory.Exists(inputValues.SourceFolder)) }
private string getFileNameFromEncodedBytes(string EncodingString, string CodePageString, byte[] FileNameBytes) { StringBuilder fileNameBuffer = new StringBuilder(); string fileNameChar; Encoding enc = null; long codePage = ByteConversion.CodePageUnitedStates; int bytesToRead; switch (EncodingString) { case "ASCII": enc = Encoding.ASCII; bytesToRead = 1; break; case "UTF8": enc = Encoding.UTF8; bytesToRead = 1; break; case "UTF16-LE": enc = Encoding.Unicode; bytesToRead = 2; break; case "UTF16-BE": enc = Encoding.BigEndianUnicode; bytesToRead = 2; break; case "UTF32-LE": enc = Encoding.UTF32; bytesToRead = 4; break; case "Code Page": // convert code page to number if (!String.IsNullOrEmpty(CodePageString)) { codePage = ByteConversion.GetLongValueFromString(CodePageString); } enc = Encoding.GetEncoding((int)(codePage)); bytesToRead = 1; break; default: enc = Encoding.ASCII; bytesToRead = 1; break; } for (int i = 0; i < FileNameBytes.Length; i += bytesToRead) { fileNameChar = enc.GetString(FileNameBytes, i, bytesToRead); if (fileNameChar.Equals(Constants.StringNullTerminator)) { break; } else { fileNameBuffer.Append(fileNameChar); } } return(fileNameBuffer.ToString()); }
//--------------- // 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); }
// DoTaskForFile protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPosFileCreatorStruct, DoWorkEventArgs e) { PosFileCreatorStruct posStruct = (PosFileCreatorStruct)pPosFileCreatorStruct; WorkingItemStruct currentItem = new WorkingItemStruct(); long loopStartValue = DEFAULT_LOOP_VALUE; long loopEndValue = DEFAULT_LOOP_VALUE; string outputFileMask; string[] outputFileList; outputFileMask = posStruct.OutputFileMask.Replace(FILEMASK_BASE_NAME, Path.GetFileNameWithoutExtension(pPath)); outputFileMask = outputFileMask.Replace(FILEMASK_EXTENSION, Path.GetExtension(pPath).Remove(0, 1)); #region LOOP POINTS using (FileStream fs = File.OpenRead(pPath)) { currentItem.Initialize(); try { //---------------- // Get Loop Start //---------------- if (posStruct.DoLoopStartStatic) { loopStartValue = ByteConversion.GetLongValueFromString(posStruct.LoopStartStaticValue); } else if (posStruct.DoLoopStartOffset) { loopStartValue = ParseFile.GetCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartCalculatingOffset, true); } else if (posStruct.DoLoopStartRiffOffset) { try { loopStartValue = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartRiffCalculatingOffset, true); } catch (IndexOutOfRangeException iorEx) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("Error processing RIFF Loop Start for <{0}>: {1}{2}", Path.GetFileName(pPath), iorEx.Message, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } else if (posStruct.DoLoopStartByteStringOffset) { loopStartValue = ParseFile.GetByteSearchCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartByteSearchCalculatingOffset, true); } if ((loopStartValue != DEFAULT_LOOP_VALUE) && ((int)loopStartValue >= 0)) { //---------------- // Get Loop End //---------------- if (posStruct.DoLoopEndStatic) { loopEndValue = ByteConversion.GetLongValueFromString(posStruct.LoopEndStaticValue); } else if (posStruct.DoLoopEndOffset) { loopEndValue = ParseFile.GetCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndCalculatingOffset, true); } else if (posStruct.DoLoopEndRiffOffset) { try { loopEndValue = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndRiffCalculatingOffset, true); } catch (IndexOutOfRangeException iorEx) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("Error processing RIFF Loop End for <{0}>: {1}{2}", Path.GetFileName(pPath), iorEx.Message, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } else if (posStruct.DoLoopEndByteStringOffset) { loopEndValue = ParseFile.GetByteSearchCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndByteSearchCalculatingOffset, true); } if ((loopEndValue != DEFAULT_LOOP_VALUE) && (loopEndValue >= 0)) { // Calculate Loop End if Needed if (posStruct.LoopEndIsLoopLength) { loopEndValue += loopStartValue; } if (loopStartValue < loopEndValue) { // update working item currentItem.LoopStart = loopStartValue; currentItem.LoopEnd = loopEndValue; } else { throw new Exception(String.Format("Loop Start Value greater than or equal Loop End Value: {0}", pPath)); } } else { throw new IndexOutOfRangeException(String.Format("Loop End Value not Found or Loop End is Less than 0: {0}", pPath)); } } else { throw new IndexOutOfRangeException(String.Format("Loop Start Value not Found or Loop Start is Less than 0: {0}", pPath)); } } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("Cannot find loop points for <{0}>: {1}{2}", Path.GetFileName(pPath), ex.Message, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } #endregion #region LOOP SHIFT // get list of matching WAV files outputFileList = Directory.GetFiles(Path.GetDirectoryName(pPath), outputFileMask, SearchOption.TopDirectoryOnly); // loop over list and add each item to the dictionary foreach (string outputFile in outputFileList) { // only shift valid values if ((loopStartValue != DEFAULT_LOOP_VALUE) && (loopEndValue != DEFAULT_LOOP_VALUE)) { // Static Loop Shift if (posStruct.DoStaticLoopShift) { // update shift currentItem.LoopShift = ByteConversion.GetLongValueFromString(posStruct.StaticLoopShiftValue); } else if (posStruct.DoLoopShiftWavCompare) // Wav Compare { // get samplecount for this file currentItem.WavSamples = GetSampleCountForRiffHeaderedFile(outputFile); currentItem.SampleDifference = currentItem.WavSamples - currentItem.LoopEnd; // update shift currentItem.LoopShift = currentItem.SampleDifference; } } this.WorkingList.Add(outputFile, currentItem); } #endregion }
public static bool ValidateInputs(GenhCreatorStruct pGenhCreatorStruct, out string pErrorMessages) { bool isValid = true; long dummy; StringBuilder errorBuffer = new StringBuilder(); // Paths if (pGenhCreatorStruct.SourcePaths.GetLength(0) < 1) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageNoInputs"]); errorBuffer.Append(Environment.NewLine); } // Header Skip if (String.IsNullOrEmpty(pGenhCreatorStruct.HeaderSkip.Trim())) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageHeaderSkip"]); errorBuffer.Append(Environment.NewLine); } // Raw Data Size if (!String.IsNullOrWhiteSpace(pGenhCreatorStruct.RawDataSize)) { dummy = ByteConversion.GetLongValueFromString(pGenhCreatorStruct.RawDataSize); if (dummy < 1) { isValid = false; errorBuffer.Append("Raw Data Size must be greater than zero."); errorBuffer.Append(Environment.NewLine); } } // Interleave if (String.IsNullOrEmpty(pGenhCreatorStruct.Interleave.Trim())) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageInterleave"]); errorBuffer.Append(Environment.NewLine); } // Channels if (String.IsNullOrEmpty(pGenhCreatorStruct.Channels.Trim())) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageChannels"]); errorBuffer.Append(Environment.NewLine); } // Frequency if (String.IsNullOrEmpty(pGenhCreatorStruct.Frequency.Trim()) && String.IsNullOrEmpty(pGenhCreatorStruct.FrequencyOffsetDescription.OffsetValue)) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageFrequency"]); errorBuffer.Append(Environment.NewLine); } // Loop Start if (!pGenhCreatorStruct.NoLoops && !pGenhCreatorStruct.FindLoop && String.IsNullOrEmpty(pGenhCreatorStruct.LoopStart.Trim()) && String.IsNullOrEmpty(pGenhCreatorStruct.LoopStartOffsetDescription.OffsetValue)) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageLoopStart1"]); errorBuffer.Append(Environment.NewLine); } else if (!pGenhCreatorStruct.NoLoops && !pGenhCreatorStruct.FindLoop && !String.IsNullOrEmpty(pGenhCreatorStruct.LoopStart) && VGMToolbox.util.ByteConversion.GetLongValueFromString(pGenhCreatorStruct.LoopStart.Trim()) < 0) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageLoopStart2"]); errorBuffer.Append(Environment.NewLine); } // Loop End if (!pGenhCreatorStruct.NoLoops && !pGenhCreatorStruct.UseFileEnd && !pGenhCreatorStruct.FindLoop && String.IsNullOrEmpty(pGenhCreatorStruct.LoopEnd.Trim()) && String.IsNullOrEmpty(pGenhCreatorStruct.LoopEndOffsetDescription.OffsetValue)) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageLoopEnd"]); errorBuffer.Append(Environment.NewLine); } // Total Samples if (pGenhCreatorStruct.NoLoops && ((String.IsNullOrWhiteSpace(pGenhCreatorStruct.TotalSamples) && String.IsNullOrWhiteSpace(pGenhCreatorStruct.TotalSamplesOffsetDescription.OffsetValue)) || ByteConversion.GetLongValueFromString(pGenhCreatorStruct.TotalSamples) < 1) && !GenhUtil.CanConvertBytesToSamples(pGenhCreatorStruct.Format)) { isValid = false; errorBuffer.Append("The following formats require a value greater than 0 (or Offset) for 'Total Samples' if no 'Loop End' is identified: MPEG, XMA, XMA2, FFMPEG."); errorBuffer.Append(Environment.NewLine); } // Skip Samples if (pGenhCreatorStruct.SkipSamplesMode == Genh.SKIP_SAMPLES_MODE_FORCE && String.IsNullOrWhiteSpace(pGenhCreatorStruct.SkipSamples)) { isValid = false; errorBuffer.Append("Skip Samples cannot be empty if 'Force Skip Samples' is checked."); errorBuffer.Append(Environment.NewLine); } // Right Coef if (pGenhCreatorStruct.Format.Equals("12") && String.IsNullOrEmpty(pGenhCreatorStruct.CoefRightChannel.Trim())) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageCoefRight"]); errorBuffer.Append(Environment.NewLine); } // Left Coef if (pGenhCreatorStruct.Format.Equals("12") && String.IsNullOrEmpty(pGenhCreatorStruct.CoefLeftChannel.Trim())) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageCoefLeft"]); errorBuffer.Append(Environment.NewLine); } // Find Loop End if (pGenhCreatorStruct.UseFileEnd && pGenhCreatorStruct.Format.Equals("8")) { isValid = false; errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageFileEnd"]); errorBuffer.Append(Environment.NewLine); } pErrorMessages = errorBuffer.ToString(); return(isValid); }
private void bytesToSamplesToolStripMenuItem_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { try { long loopValue = 0; long headerValue = 0; if (this.selectedLabel == TOTAL_SAMPLES_LABEL_SELECTED) { loopValue = ByteConversion.GetLongValueFromString(this.tbTotalSamples.Text); } else { if (this.selectedLabel == LOOP_START_LABEL_SELECTED) { loopValue = ByteConversion.GetLongValueFromString(this.tbLoopStart.Text); } else if (this.selectedLabel == LOOP_END_LABEL_SELECTED) { loopValue = ByteConversion.GetLongValueFromString(this.tbLoopEnd.Text); } if (!String.IsNullOrEmpty(this.cbHeaderSkip.Text)) { headerValue = ByteConversion.GetLongValueFromString(this.cbHeaderSkip.Text); loopValue -= headerValue; } } if (loopValue >= 0) { if (!String.IsNullOrWhiteSpace(this.cbInterleave.Text) && !String.IsNullOrWhiteSpace(this.cbChannels.Text)) { DataRowView drv = (DataRowView)this.comboFormat.SelectedItem; UInt16 formatId = Convert.ToUInt16(drv.Row.ItemArray[0]); if (GenhUtil.CanConvertBytesToSamples(formatId)) { long interleave = ByteConversion.GetLongValueFromString(this.cbInterleave.Text); long channelCount = ByteConversion.GetLongValueFromString(this.cbChannels.Text); long samplesValue = GenhUtil.BytesToSamples((int)formatId, (int)loopValue, (int)channelCount, (int)interleave); if (this.selectedLabel == LOOP_START_LABEL_SELECTED) { this.tbLoopStart.Text = samplesValue.ToString(); } else if (this.selectedLabel == LOOP_END_LABEL_SELECTED) { this.tbLoopEnd.Text = samplesValue.ToString(); } else if (this.selectedLabel == TOTAL_SAMPLES_LABEL_SELECTED) { this.tbTotalSamples.Text = samplesValue.ToString(); } } else { MessageBox.Show("Cannot convert bytes to samples for the following formats: MPEG, XMA, XMA2, FFMPEG.", "Error"); } } else { MessageBox.Show("Cannot convert bytes to samples: Please enter values for Interleave and Channels.", "Error"); } } } catch { } } }