/// <summary> /// Extracts images from Milo file and saves textures in "(miloDir)/ext_(milofilename)" /// as "texture(int)" starting from zero. /// </summary> /// <param name="inMilo">Milo file location</param> /// <param name="saveDDS">Save DDS?</param> /// <param name="saveTEX">Save TEX?</param> /// <param name="format">Format to output the images to</param> /// <param name="outTexCount">Number of textures in Milo file</param> public static void ExtractTextures(string inMilo, bool saveDDS, bool saveTEX, string format, out int outTexCount) { var texCount = 0; var Tools = new NemoTools(); var ext = Path.GetExtension(inMilo); if (string.IsNullOrWhiteSpace(ext)) { outTexCount = 0; return; } TexturesFolder = inMilo.Replace(ext, "_textures\\"); BlocksFolder = TexturesFolder + "blocks\\"; FilesFolder = TexturesFolder + "files\\"; try { // Reads first four bytes to check its compression type. var br = new BinaryReader(File.OpenRead(inMilo)); var firstFour = br.ReadBytes(4); br.Close(); string compressionType; if (firstFour.IsMilo(out compressionType)) { var count = 0; ProcessMilo(inMilo, compressionType, true, saveTEX, ref texCount, false, ref count, false, ref count); } } catch (Exception) {} outTexCount = texCount; //clean up afterwards if (outTexCount < 1) { Tools.DeleteFolder(TexturesFolder, true); } else { Tools.DeleteFolder(BlocksFolder, true); Tools.DeleteFolder(FilesFolder, true); var ddsfiles = Directory.GetFiles(TexturesFolder, "*.dds"); foreach (var dds in ddsfiles) { if (!string.IsNullOrWhiteSpace(format)) { Tools.ConvertRBImage(dds, dds, format); } if (!saveDDS) { Tools.DeleteFile(dds); } } } outTexCount = texCount; }
private void CleanUp() { if (!cleanUpAfterBundlingFiles.Checked) { return; } Tools.DeleteFolder(temp_folder, true); Directory.CreateDirectory(temp_folder); }
private void PhaseShiftPrep_FormClosing(object sender, FormClosingEventArgs e) { if (!picWorking.Visible) { Tools.DeleteFolder(Application.StartupPath + "\\phaseshift\\"); return; } MessageBox.Show("Please wait until the current process finishes", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
private void SongExplorer_FormClosing(object sender, FormClosingEventArgs e) { if (picWorking.Visible) { MessageBox.Show("Please wait until the current process finishes", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; return; } if (Changes) { if (MessageBox.Show("You have unsaved changes\nIf you exit now nothing will be changed in the file\nAre you sure you want to exit?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { e.Cancel = true; return; } } xPackage.CloseIO(); Tools.DeleteFolder(Application.StartupPath + "\\packex\\", true); Tools.DeleteFolder(Application.StartupPath + "\\temp\\", true); }
public VideoPreparer(Color ButtonBackColor, Color ButtonTextColor) { InitializeComponent(); inputFiles = new List <string>(); Tools = new NemoTools(); Parser = new DTAParser(); inputDir = Application.StartupPath + "\\videoprep_input\\"; groupBox1.AllowDrop = true; tempFolder = Application.StartupPath + "\\videoprep_temp\\"; Tools.DeleteFolder(tempFolder, true); toolTip1.SetToolTip(btnBegin, "Click to begin process"); toolTip1.SetToolTip(btnFolder, "Click to select the input folder"); toolTip1.SetToolTip(btnRefresh, "Click to refresh if the contents of the folder have changed"); toolTip1.SetToolTip(txtFolder, "This is the working directory"); toolTip1.SetToolTip(txtTitle, "Enter a title for your pack (visible in the Xbox dashboard)"); toolTip1.SetToolTip(lstLog, "This is the application log. Right click to export"); nextFriday = DateTime.Today; while (nextFriday.DayOfWeek != DayOfWeek.Friday) { nextFriday = nextFriday.AddDays(1D); } var month = "0" + nextFriday.Month; month = month.Substring(month.Length - 2, 2); var day = "0" + nextFriday.Day; day = day.Substring(day.Length - 2, 2); PackDate = month + "/" + day + "/" + nextFriday.Year.ToString(CultureInfo.InvariantCulture).Substring(2, 2); var formButtons = new List <Button> { btnFolder, btnRefresh, btnReset, btnView, btnBegin }; foreach (var button in formButtons) { button.BackColor = ButtonBackColor; button.ForeColor = ButtonTextColor; button.FlatAppearance.MouseOverBackColor = button.BackColor == Color.Transparent ? Color.FromArgb(127, Color.AliceBlue.R, Color.AliceBlue.G, Color.AliceBlue.B) : Tools.LightenColor(button.BackColor); } if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } }
public bool ConvertRBAtoCON(string rba) { if (backgroundWorker1.CancellationPending) { return(false); } if (!File.Exists(rba)) { Log("Can't find file " + rba); Log("Skipping it..."); return(false); } var success = ExtractRBA(rba); if (success) { success = makeCON(rba); } Tools.DeleteFolder(tempfolder, true); return(success); }
private void ExtractFromSaveFile(string file) { ClearAll(); isWorking(true); var savefile = file; var isXbox = Path.GetFileName(file).ToLowerInvariant().Contains("xbox") || Path.GetFileName(file) == "band3"; isWii = Path.GetFileName(file).ToLowerInvariant().Contains("wii"); isPS3 = Path.GetFileName(file).ToLowerInvariant().Contains("ps3"); Tools.CurrentFolder = Path.GetDirectoryName(file); UserSaveFile = file; if (VariousFunctions.ReadFileType(file) == XboxFileType.STFS) { isXbox = true; isPS3 = false; isWii = false; Log("Received save CON file, extracting save.dat file"); var package = new STFSPackage(file); if (!package.ParseSuccess) { isWorking(false); package.CloseIO(); Log("Couldn't read that CON file, aborting"); Log("Ready"); return; } var xent = package.GetFile("save.dat"); if (xent == null) { isWorking(false); package.CloseIO(); Log("Couldn't find save.dat in that CON file, aborting"); Log("Ready"); return; } var tempdat = EditorFolder + "\\temp.dat"; Tools.DeleteFile(tempdat); if (!xent.ExtractToFile(tempdat)) { isWorking(false); package.CloseIO(); Log("Couldn't extract save.dat from that CON file, aborting"); Log("Ready"); return; } savefile = tempdat; package.CloseIO(); } Log("Received save file, extracting images..."); ImageFolder = EditorFolder + Path.GetFileNameWithoutExtension(file) + "_extracted\\"; Tools.DeleteFolder(ImageFolder, true); var success = false; if (isXbox) { success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file)); } else if (isWii) { success = Tools.ExtractWiiSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file)); } else if (isPS3) { success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file), true); } else { switch (MessageBox.Show("Click Yes if this is a *decrypted* PS3 save file\nClick No if this is a Wii save file\nXbox 360 users must use the 'band3' save file\nPress Cancel to go back", Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)) { case DialogResult.Yes: isPS3 = true; isWii = false; success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file), true); break; case DialogResult.No: isWii = true; isPS3 = false; success = Tools.ExtractWiiSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file)); break; case DialogResult.Cancel: Log("Extracting cancelled by user"); isWorking(false); Log("Ready"); return; } } if (!success) { Log("Extracting from save game file failed"); isWorking(false); Log("Ready"); return; } Log("Extracted images from save file successfully"); if (savefile != file) //i.e. extracted from con { Tools.DeleteFile(savefile); } lblFileName.Text = Path.GetFileName(file); lblConsole.Text = isPS3 ? "Playstation 3" : (isWii ? "Wii" : "Xbox 360"); ChangeImagePadding(); LoadExtractedImages(); exportAllImagesToolStripMenuItem.Enabled = true; closeFileToolStripMenuItem.Enabled = true; txtBand.Enabled = true; txtBand.Text = !string.IsNullOrWhiteSpace(Tools.SaveFileBandName) ? Tools.SaveFileBandName : "Unknown"; txtBand.ReadOnly = isWii; isWorking(false); Log("Ready"); }
private void btnClose_Click(object sender, EventArgs e) { Tools.DeleteFolder(testfolder, true); Close(); }
private bool extractRBFiles() { var counter = 0; var success = 0; foreach (var file in inputFiles) { if (backgroundWorker1.CancellationPending) { return(false); } try { if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS) { continue; } try { counter++; Parser.ExtractDTA(file); Parser.ReadDTA(Parser.DTA); if (Parser.Songs.Count > 1) { Log("File " + Path.GetFileName(file) + " is a pack, try dePACKing first, skipping..."); continue; } var xPackage = new STFSPackage(file); if (!xPackage.ParseSuccess) { Log("Failed to extract '" + Path.GetFileName(file) + "'"); Log("Skipping this file"); } //if working inner temp folder exists, delete to start clean var temptempFile = tempFolder + "temp\\"; Tools.DeleteFolder(temptempFile, true); if (backgroundWorker1.CancellationPending) { xPackage.CloseIO(); return(false); } //extract songs folder, subfolders and all files into a combined directory xPackage.ExtractPayload(temptempFile, true, false); xPackage.CloseIO(); temptempFile = temptempFile + "root\\"; if (Directory.Exists(temptempFile + "songs\\")) { var subFolders = Directory.GetDirectories(temptempFile + "songs\\"); var tempFileName = subFolders[0].Substring((temptempFile + "songs\\").Length, subFolders[0].Length - (temptempFile + "songs\\").Length); if (subFolders.Count() != 0) //upgrades won't have subdirectories, skip this step in that case { if (File.Exists(temptempFile + "songs\\songs.dta")) { //move songs.dta to the song's folder for sorting later //allows to skip duplicates Tools.MoveFile(temptempFile + "songs\\songs.dta", temptempFile + "songs\\" + tempFileName + "\\songs.dta"); } foreach (var foldertoMove in subFolders) { tempFileName = foldertoMove.Substring((temptempFile + "songs\\").Length, foldertoMove.Length - (temptempFile + "songs\\").Length); var folderpath = tempFolder + "songs\\"; //let's make sure songs folder is there, if not, create it if (!(Directory.Exists(folderpath))) { Directory.CreateDirectory(tempFolder + "songs\\"); } //if this song already exists in the working directory, delete it //copy this one instead Tools.DeleteFolder(folderpath + tempFileName + "\\", true); if (Path.GetPathRoot(temptempFile) == Path.GetPathRoot(songsFolder)) { Directory.Move(temptempFile + "songs\\" + tempFileName + "\\", folderpath + tempFileName + "\\"); } else { FileSystem.CopyDirectory(temptempFile + "songs\\" + tempFileName + "\\", folderpath + tempFileName + "\\"); } } } Log("Extracting file " + counter + " of " + inputFiles.Count); success++; } //move other root files but no spa.bin files to root directory var rootFiles = Directory.GetFiles(temptempFile); if (rootFiles.Count() != 0) { foreach (var rootFile in rootFiles.Where(rootFile => rootFile.Substring(rootFile.Length - 7, 7) != "spa.bin")) { Tools.MoveFile(rootFile, tempFolder + Path.GetFileName(rootFile)); } } //delete folder to get rid of useless files Tools.DeleteFolder(temptempFile, true); } catch (Exception ex) { Log("There was an error: " + ex.Message); return(false); } } catch (Exception ex) { Log("There was a problem accessing that file"); Log("The error says: " + ex.Message); } } Log("Successfully extracted " + success + " of " + counter + " files"); return(true); }