private void btnDoTask_Click(object sender, EventArgs e) { string errorMessages; this.initializeProcessing(); GenhCreatorStruct genhStruct = this.getGenhParameters(); if ((!rbExtract.Checked) && (!ValidateInputs(genhStruct, out errorMessages))) { MessageBox.Show(errorMessages, ConfigurationManager.AppSettings["Form_GenhCreator_MessageErrors"]); this.errorFound = true; this.setNodeAsComplete(); } else { base.backgroundWorker_Execute(genhStruct); } }
private void showLoopPointsForSelectedFile() { if (lbFiles.SelectedIndices.Count == 1) { string dummy; string loopStartFound = this.tbLoopStart.Text; string loopEndFound = this.tbLoopEnd.Text; GenhCreatorStruct genhStruct = this.getGenhParameters(); if (ValidateInputs(genhStruct, out dummy)) { try { if (genhStruct.UseFileEnd) { loopEndFound = GenhUtil.GetTotalSamples(genhStruct.SourcePaths[0], genhStruct.ToGenhCreationStruct()); } else if (genhStruct.FindLoop) { if ((!isPs2AdpcmSelected()) || (!GenhUtil.GetPsAdpcmLoop(genhStruct.SourcePaths[0], genhStruct.ToGenhCreationStruct(), out loopStartFound, out loopEndFound))) { loopStartFound = String.Empty; loopEndFound = String.Empty; } } this.tbLoopStart.Text = loopStartFound; this.tbLoopEnd.Text = loopEndFound; } catch (Exception ex) { this.tbLoopStart.Clear(); this.tbLoopEnd.Clear(); this.tbOutput.Clear(); this.tbOutput.Text += String.Format("{0}{1}", ex.Message, Environment.NewLine); } } } }
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 GenhCreatorStruct getGenhParameters() { ListBoxFileInfoObject listBoxFile; GenhCreatorStruct genhStruct = new GenhCreatorStruct(); DataRowView drv = (DataRowView)this.comboFormat.SelectedItem; genhStruct.DoCreation = this.rbCreate.Checked; genhStruct.DoEdit = this.rbEdit.Checked; genhStruct.DoExtract = this.rbExtract.Checked; genhStruct.Format = Convert.ToUInt16(drv.Row.ItemArray[0]).ToString(); genhStruct.HeaderSkip = this.cbHeaderSkip.Text; genhStruct.Interleave = this.cbInterleave.Text; genhStruct.UseInterleaveOffset = this.cbUseInterleaveOffset.Checked; genhStruct.InterleaveOffsetDescription = this.interleaveOffsetDescription.GetOffsetValues(); genhStruct.Channels = this.cbChannels.Text; genhStruct.UseChannelsOffset = this.cbUseChannelsOffset.Checked; genhStruct.ChannelsOffsetDescription = this.channelsOffsetDescription.GetOffsetValues(); genhStruct.Frequency = this.cbFrequency.Text; genhStruct.UseFrequencyOffset = this.cbUseFrequencyOffset.Checked; genhStruct.FrequencyOffsetDescription = this.frequencyOffsetDescription.GetOffsetValues(); genhStruct.LoopStart = this.tbLoopStart.Text; genhStruct.UseLoopStartOffset = this.cbUseLoopStartOffset.Checked; genhStruct.LoopStartOffsetDescription = this.loopStartOffsetDescription.GetOffsetValues(); genhStruct.DoLoopStartBytesToSamples = this.cbLoopStartBytesToSamples.Checked; genhStruct.LoopEnd = this.tbLoopEnd.Text; genhStruct.UseLoopEndOffset = this.cbUseLoopEndOffset.Checked; genhStruct.LoopEndOffsetDescription = this.loopEndOffsetDescription.GetOffsetValues(); genhStruct.DoLoopEndBytesToSamples = this.cbLoopEndBytesToSamples.Checked; genhStruct.TotalSamples = this.tbTotalSamples.Text; genhStruct.UseTotalSamplesOffset = this.cbUseTotalSamplesOffset.Checked; genhStruct.TotalSamplesOffsetDescription = this.totalSamplesOffsetDescription.GetOffsetValues(); genhStruct.DoTotalSamplesBytesToSamples = this.cbTotalSamplesBytesToSamples.Checked; genhStruct.SkipSamplesMode = this.cbForceSkipSamples.Checked ? Genh.SKIP_SAMPLES_MODE_FORCE : Genh.SKIP_SAMPLES_MODE_AUTODETECT; genhStruct.SkipSamples = this.tbForceSkipSamplesNumber.Text; genhStruct.Atrac3StereoMode = (byte)this.cbAtrac3StereoMode.SelectedIndex; genhStruct.XmaStreamMode = (byte)this.cbXmaStreamMode.SelectedIndex; genhStruct.RawDataSize = String.IsNullOrWhiteSpace(this.tbRawDataSize.Text)? "0": this.tbRawDataSize.Text; drv = (DataRowView)this.cbCoefficientType.SelectedItem; genhStruct.NoLoops = this.cbNoLoops.Checked; genhStruct.UseFileEnd = this.cbLoopFileEnd.Checked; genhStruct.FindLoop = this.cbFindLoop.Checked; genhStruct.CoefRightChannel = this.tbRightCoef.Text; genhStruct.CoefLeftChannel = this.tbLeftCoef.Text; genhStruct.CoefficientType = Convert.ToByte(drv.Row.ItemArray[0]); genhStruct.OutputHeaderOnly = this.cbHeaderOnly.Checked; genhStruct.SourcePaths = new string[this.lbFiles.SelectedIndices.Count]; int j = 0; foreach (int i in this.lbFiles.SelectedIndices) { listBoxFile = (ListBoxFileInfoObject)this.lbFiles.Items[i]; genhStruct.SourcePaths[j++] = listBoxFile.FilePath; } return(genhStruct); }