public ReadFile(ImportFileType importFileType) { SettingsImportSF settings = new SettingsImportSF(); fileName = settings.GetFileName(importFileType); if (!File.Exists(fileName)) { LogManager.Logger.Information("File " + importFileType.ToString() + " not found"); return; } string[] lines = File.ReadAllLines(fileName); SplitLines(lines); }
private void convertToBinFileButton_Click(object sender, EventArgs e) { //Are we using PVR or BMP? importFileType = bmpRadioButton.Checked ? ImportFileType.PNG : ImportFileType.PVR; ImportErrorLabel.Text = String.Empty; ImportSuccessLabel.Text = String.Empty; if (String.IsNullOrEmpty(ExportedBinOutputDirectoryTextBox.Text)) { ImportErrorLabel.Text = "Please enter an output directory for the .bin file"; return; } if (String.IsNullOrEmpty(FilesToImportDirectory.Text)) { ImportErrorLabel.Text = "Please enter a directory for where the ." + importFileType.ToString() + " file(s) are located"; return; } //If using bitmaps, make sure a config file exists PVRConfig config = null; if (importFileType == ImportFileType.PNG) { try { config = new PVRConfig(); config.Load(FilesToImportDirectory.Text + "/" + Preferences.PVR_CONFIG_FILENAME); } catch { ImportErrorLabel.Text = "Cannot find the file \"" + Preferences.PVR_CONFIG_FILENAME + "\". Please locate it"; return; } } int numFiles = 0; String outFile = null; JSR.Character character = JSR.Character.Gum; JSR.Stage stage = JSR.Stage.ShibuyaArea3Part1; if (Mode == TextureModderMode.Character) { CharacterTexture sc; try { sc = textures.characterTextures.Where(ct => ct.GetName() == comboBox1.Text).First(); } catch (Exception ex) { ImportErrorLabel.Text = "Please select a character"; return; } numFiles = sc.GetNumPvrFiles(); outFile = sc.GetFileName(); character = sc.GetCharacter(); } else if (Mode == TextureModderMode.Stage) { StageTexture ss; try { ss = textures.StageTextures.Where(st => st.GetName() == comboBox1.Text).First(); } catch (Exception ex) { ImportErrorLabel.Text = "Please select a stage"; return; } numFiles = ss.GetNumPvrFiles(); outFile = ss.GetFileName(); stage = ss.GetStage(); } //Find the RIPPED_X files List <List <Byte> > pvrData = new List <List <Byte> >(); try { for (int i = 0; i < numFiles; i++) { if (importFileType == ImportFileType.PVR) { pvrData.Add(new List <Byte>()); pvrData[i].AddRange(System.IO.File.ReadAllBytes(FilesToImportDirectory.Text + "/RIPPED_" + i + ".pvr")); Console.WriteLine("Added RIPPED_" + i + ".pvr"); } else if (importFileType == ImportFileType.PNG) { //Load the bitmap - if the png file doesn't exist, the decode may have failed so we need to hunt for the PVR File Bitmap bitmap; try { bitmap = (Bitmap)Bitmap.FromFile(FilesToImportDirectory.Text + "/RIPPED_" + i + ".png"); } catch (System.IO.FileNotFoundException) { //Look for PVR pvrData.Add(new List <Byte>()); pvrData[i].AddRange(System.IO.File.ReadAllBytes(FilesToImportDirectory.Text + "/RIPPED_" + i + ".pvr")); Console.WriteLine("Added RIPPED_" + i + ".pvr"); continue; } var data = config.Get(i); //Bit of a hack, but run pvrconv from command line, saves PVR importing having to be done //First convert png to bmp var adjustedDepthBitmap = new Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(adjustedDepthBitmap)) { g.DrawImage(bitmap, new Rectangle(0, 0, adjustedDepthBitmap.Width, adjustedDepthBitmap.Height)); adjustedDepthBitmap.Save(FilesToImportDirectory.Text + "/RIPPED_" + i + ".bmp", ImageFormat.Bmp); } //Get the location of pvrconv String exeLoc = "\"" + (Preferences.PVR_CONV_EXE_LOCATION == String.Empty ? String.Empty : Preferences.PVR_CONV_EXE_LOCATION + "/"); exeLoc += "pvrconv.exe\""; var cmd = data.ToPVRConvFlags() + " \"" + FilesToImportDirectory.Text + "/RIPPED_" + i + ".bmp\""; var process = new System.Diagnostics.Process(); process.StartInfo.FileName = exeLoc; process.StartInfo.Arguments = cmd; process.Start(); process.WaitForExit(); Console.WriteLine("Added RIPPED_" + i + ".png"); //Add PVR file data pvrData.Add(new List <Byte>()); pvrData[i].AddRange(System.IO.File.ReadAllBytes(FilesToImportDirectory.Text + "/RIPPED_" + i + ".pvr")); Console.WriteLine("Added RIPPED_" + i + ".pvr"); //Clean up files System.IO.File.Delete(FilesToImportDirectory.Text + "/RIPPED_" + i + ".bmp"); System.IO.File.Delete(FilesToImportDirectory.Text + "/RIPPED_" + i + ".pvr"); } } } catch (Exception ex) { ImportErrorLabel.Text = ex.Message; return; } try { if (Mode == TextureModderMode.Character) { System.IO.File.WriteAllBytes(ExportedBinOutputDirectoryTextBox.Text + "/" + outFile, JSReverse.JSR.PVRToBin(character, pvrData)); } else if (Mode == TextureModderMode.Stage) { System.IO.File.WriteAllBytes(ExportedBinOutputDirectoryTextBox.Text + "/" + outFile, JSReverse.JSR.PVRToTXP(stage, pvrData)); } } catch (Exception ex) { ImportErrorLabel.Text = ex.Message; return; } ImportSuccessLabel.Text = "Success!"; }
private bool Import(string dtsPackagePath, string dtsArguments, string posUpdateSPName, ref string messageString) { this.Cursor = Cursors.WaitCursor; progressBar1.Visible = true; bool importError = false; string DTExecPath = ConfigurationManager.AppSettings["DTExecPath"]; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = DTExecPath; process.StartInfo.Arguments = dtsArguments; process.StartInfo.WorkingDirectory = DTExecPath.ToLower().Replace("dtexec.exe", string.Empty); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.ErrorDialog = true; //using (System.IO.StreamWriter sw = new System.IO.StreamWriter(ConfigurationManager.AppSettings["DTSErrorFilePath"], true)) //{ // sw.Write("DTS Error on: "); // sw.WriteLine(CommentOverrideDateTime.Now); // sw.WriteLine(string.Format("process.StartInfo.FileName: {0}", process.StartInfo.FileName)); // sw.WriteLine(string.Format("process.StartInfo.Arguments: {0}", process.StartInfo.Arguments)); // sw.WriteLine(string.Format("process.StartInfo.WorkingDirectory: {0}", process.StartInfo.WorkingDirectory)); //} process.Start(); string output = process.StandardOutput.ReadToEnd(); process.WaitForExit(300000); // wait for 5 mins importError = process.ExitCode != 0; if (importError) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(ConfigurationManager.AppSettings["DTSErrorFilePath"], true)) { sw.Write("DTS Error on: "); sw.WriteLine(DateTime.Now); sw.WriteLine(output); } messageString = string.Format("Error occured while loading the {0} file to temporary SQL table.", _importFileType.ToString()); } else { SqlConnection connection = new SqlConnection(_connectionString); SqlCommand command = new SqlCommand(); command.CommandText = posUpdateSPName; command.CommandType = CommandType.StoredProcedure; if (_customerKey != null) { command.Parameters.AddWithValue("@company_code", _customerKey.CompanyCode); command.Parameters.AddWithValue("@customer_number", _customerKey.CustomerNumber); } command.CommandTimeout = 0; command.Connection = connection; connection.Open(); string POSorActualSales = _importFileType == ImportFileType.ActualSalesFlat ? "Actual Sales" : "POS"; System.Text.StringBuilder sb = new StringBuilder(string.Empty); using (SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection)) { if (dr.Read()) { importError = (int)(dr["errorNumber"]) != 0; if (importError) { sb.Append(string.Format("Error occured while updating {0} from temporary {1} table.", POSorActualSales, POSorActualSales)); sb.Append("\nData has been rolled back to previous good state."); sb.Append("\nError Number: ").Append(dr["errorNumber"].ToString()); sb.Append("\nError Message: ").Append(dr["errorMessage"].ToString()); sb.Append("\nError Severity: ").Append(dr["errorSeverity"].ToString()); sb.Append("\nError State: ").Append(dr["errorState"].ToString()); sb.Append("\nLine Number: ").Append(dr["errorLine"].ToString()); sb.Append("\nProcedure Name: ").Append(dr["errorProcedure"].ToString()); } else { sb.Append(string.Format("{0} import from {1} file succeeded.", POSorActualSales, _importFileType.ToString())); sb.Append("\nRows backed up: ").Append(dr["rowBackedUp"].ToString()); sb.Append("\nDuplicate rows deleted: ").Append(dr["duplicateRowDeleted"].ToString()); sb.Append("\nRows inserted: ").Append(dr["rowInserted"].ToString()); } } } messageString = sb.ToString(); } progressBar1.Visible = false; this.Cursor = Cursors.Arrow; return(importError); }