private bool InitializeTargetDirectory() { if (mConsoleCopy) { if (!XboxUtils.FileExist(mSyncRoot)) { if (!XboxUtils.DirectoryCreateVerify(mSyncRoot, true)) { // Error //MOG_REPORT.ShowMessageBox("Xbox Dir Error", string.Concat(mSyncRoot, " could not be created!"), MessageBoxButtons.OK); throw new Exception(mSyncRoot + " could not be created!"); } } } else { // Create the initial directory on the pc if (!DosUtils.Exist(mSyncRoot)) { try { Directory.CreateDirectory(mSyncRoot); } catch (Exception e) { // Error MOG_REPORT.ShowMessageBox("Dir Error", string.Concat(mSyncRoot, " could not be created!", "\n", e.ToString()), MessageBoxButtons.OK); throw new Exception(mSyncRoot + " could not be created!", e); //return false; } } } return(true); }
private bool CreateTargetDirectoryPath(string targetPath) { // Check for a sub-dir int index = targetPath.LastIndexOf("\\"); if (index != -1 && targetPath[index - 1] != ':') { string RootDir = targetPath.Substring(0, index); if (!CreateTargetDirectoryPath(RootDir)) { return(false); } } if (mConsoleCopy) { // Check if it already exists if (!XboxUtils.FileExist(targetPath)) { // if (!XboxUtils.DirectoryCreateVerify(targetPath, false)) { // Error MOG_REPORT.ShowMessageBox("Create Target Directory Path", string.Concat(RemapDirectoryString(targetPath), " could not be created!"), MessageBoxButtons.OK); return(false); } XboxUtils.DM_FILE_ATTRIBUTES att = new XboxUtils.DM_FILE_ATTRIBUTES(); XboxUtils.GetFileAttributes(targetPath, ref att); if (!(att.SizeHigh != 0 && att.SizeLow != 0)) { // Error MOG_REPORT.ShowMessageBox("Create Target Directory Path", string.Concat(RemapDirectoryString(targetPath), " could not be created!"), MessageBoxButtons.OK); return(false); } } } else { // Check if it already exists if (!DosUtils.FileExist(targetPath)) { // try { Directory.CreateDirectory(targetPath); } catch (Exception e) { // Error MOG_REPORT.ShowMessageBox("Create Directory Error", string.Concat(RemapDirectoryString(targetPath), " could not be created!", "\n", e.ToString()), MessageBoxButtons.OK); return(false); } } } return(true); }
private bool InitializeFileCounts() { bool success = true; mGetFileCount = true; mTotalFilesToCopy = 0; mProgress.DialogInitialize("(" + mTargetConsole + ")Platform Data Sync", "Calculating total files to be copied:\nThis may take a few seconds...", ""); for (int i = 0; i < mPlatformSync.CountKeys("FileMap"); i++) { string sourcePath = FormatString(mPlatformSync.GetKeyNameByIndex("FileMap", i).ToLower()); string targetPath = sourcePath.Replace(mSourcePath, mSyncRoot); string filePattern = mPlatformSync.GetKeyByIndex("FileMap", i).ToLower(); success = SyncDirectories(sourcePath, filePattern, mSyncRoot); mProgress.DialogUpdate((i * 100) / mPlatformSync.CountKeys("FileMap"), "Scanning:\n" + targetPath); Application.DoEvents(); // Create the needed directory on the xbox string newDirName = RemapDirectoryString(targetPath); if (mConsoleCopy) { if (!XboxUtils.FileExist(newDirName)) { mPendingCopy.PutSectionString("CREATE_DIR", newDirName); mPendingCopy.Save(); } else { mPendingCopy.PutSectionString("DIR_EXISTS", newDirName); mPendingCopy.Save(); } } else { if (!DosUtils.FileExist(newDirName)) { mPendingCopy.PutSectionString("CREATE_DIR", newDirName); mPendingCopy.Save(); } } // Check if the user has canceled if (!success) { throw new Exception("User canceled the opperation"); } } return(true); }
public void TargetXboxMakeLinearLoadIso() { // Optimize all the data string output = ""; string sourceDir = mainForm.mAssetManager.GetTargetPath(); string userName = mMog.GetUser().GetUserName(); bool useDefault = false; CallbackDialogForm bigProgress = new CallbackDialogForm(); bigProgress.DialogInitialize("Make Linear Load Build", "Creating linear maps...\nThis could take many hours", "Cancel"); // Use 'default' as user, if the Default checkbox is checked. This is used for the programmers who debug their code using the default.xbe if (mainForm.AssetManagerLocalDataXboxDefaultCheckBox.Checked) { userName = "******"; useDefault = true; } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } // Get the tool listed on the startup page string command = "[ProjectPath]\\Mog\\Tools\\Xbox\\Optimize\\Optimize.bat"; if (command.IndexOf("[ProjectPath]") != -1) { command = string.Concat(command.Substring(0, command.IndexOf("[")), mainForm.mAssetManager.GetTargetPath(), command.Substring(command.IndexOf("]") + 1)); } bigProgress.DialogUpdate(10, "Optimizing the newly merged data"); // Make sure the tool we need exits if (DosUtils.FileExist(command)) { // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } if (guiCommandLine.ShellExecute(command, mainForm.mAssetManager.GetTargetPath() + "\\System", ProcessWindowStyle.Normal, ref output) != 0) { MOG_REPORT.ShowMessageBox("XBox Tools", string.Concat(output), MessageBoxButtons.OK); } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } bigProgress.DialogUpdate(20, "Syncing to Build Xbox for linear load tool execution..."); // Sync to the Linear Build xbox string buildXbox = "LinearBuild"; // Logon to correct xbox XboxUtils.SetXboxName(buildXbox, false); guiPlatformSinc sinc = new guiPlatformSinc(buildXbox, mainForm.mAssetManager.GetTargetPath(), mainForm, userName, useDefault, false, false, false); sinc.mProjectSyncFile = "xbox.opt.ls.sync"; sinc.mUserSyncFile = ""; sinc.TargetConsoleSync(); // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } // Run the linear load tool string xboxExe = "xE:\\" + mMog.GetProject().GetProjectName() + "\\defaultls.xbe"; bigProgress.DialogUpdate(30, "Preparing for linear load tool execution..."); // Kill the Linear load complete file in the root before we call the tool if (XboxUtils.FileExist("xQ:\\LoadComplete.sys")) { XboxUtils.FileDelete("xQ:\\LoadComplete.sys"); } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } // Kill all previous linear files string LinearLoadFiles = XboxUtils.GetFiles("xE:\\" + mMog.GetProject().GetProjectName() + "\\System\\"); if (LinearLoadFiles.Length != 0 && LinearLoadFiles.IndexOf(",") != -1) { CallbackDialogForm progress1 = new CallbackDialogForm(); progress1.DialogInitialize("Make Linear Load Build", "Deleting previous linear load maps...", "Cancel"); string [] files = LinearLoadFiles.Split(",".ToCharArray()); foreach (string file in files) { if (string.Compare(Path.GetExtension(file), ".lin", true) == 0) { progress1.DialogUpdate(0, file); XboxUtils.FileDelete(file); // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { progress1.DialogKill(); bigProgress.DialogKill(); return; } if (progress1.DialogProcess()) { progress1.DialogKill(); return; } } } progress1.DialogKill(); } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } MOG_Ini buttonDefaults = null; if (mMog.IsProject()) { // Get the project defaults string projectDefaultButtonsFile = mMog.GetProject().GetProjectToolsPath() + "\\" + mMog.GetProject().GetProjectName() + ".Client.Buttons.Default.info"; if (DosUtils.FileExist(projectDefaultButtonsFile)) { buttonDefaults = new MOG_Ini(projectDefaultButtonsFile); } } // Get the tool listed on the startup page if (buttonDefaults != null) { if (buttonDefaults.SectionExist(mMog.GetProject().GetProjectName() + ".Buttons")) { if (buttonDefaults.KeyExist(mMog.GetProject().GetProjectName() + ".Buttons", "Run")) { command = buttonDefaults.GetString(mMog.GetProject().GetProjectName() + ".Buttons", "Run"); } } } if (command.IndexOf("[ProjectPath]") != -1) { command = string.Concat(command.Substring(0, command.IndexOf("[")), mainForm.mAssetManager.GetTargetPath(), command.Substring(command.IndexOf("]") + 1)); } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } bigProgress.DialogUpdate(50, "Starting the linear load creation tool..."); // Make sure the tool we need exits if (DosUtils.FileExist(command)) { if (guiCommandLine.ShellExecute(command, string.Concat("/x ", buildXbox, " ", xboxExe), ProcessWindowStyle.Hidden, ref output) != 0) { MOG_REPORT.ShowMessageBox("XBox Tools", string.Concat(output), MessageBoxButtons.OK); } // Wait till the LinearLoad.sys file exists before continuing... while (XboxUtils.FileExist("Q:\\LoadComplete.sys") == false) { Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } Thread.Sleep(500); } } else { MOG_REPORT.ShowMessageBox("XBox Tools", string.Concat("This tool is missing, have you updated to the latest version?"), MessageBoxButtons.OK); } // Kill the Linear load complete file once we are done if (XboxUtils.FileExist("xQ:\\LoadComplete.sys")) { XboxUtils.FileDelete("xQ:\\LoadComplete.sys"); } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } bigProgress.DialogUpdate(80, "Retrieving linear load maps from Build Xbox..."); // Copy off the data LinearLoadFiles = XboxUtils.GetFiles("xE:\\" + mMog.GetProject().GetProjectName() + "\\System\\"); if (LinearLoadFiles.Length != 0 && LinearLoadFiles.IndexOf(",") != -1) { CallbackDialogForm progress = new CallbackDialogForm(); progress.DialogInitialize("Make Linear Load Build", "Copying completed linear load maps...", "Cancel"); string [] files = LinearLoadFiles.Split(",".ToCharArray()); foreach (string file in files) { if (string.Compare(Path.GetExtension(file), ".lin", true) == 0) { string target = mMog.GetActivePlatform().mPlatformTargetPath + "\\xboxdata\\maps\\" + Path.GetFileName(file); progress.DialogUpdate(0, target); // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { progress.DialogKill(); bigProgress.DialogKill(); return; } if (progress.DialogProcess()) { progress.DialogKill(); break; } if (!XboxUtils.FileGet(file, target, false)) { MOG_REPORT.ShowMessageBox("Make Linear Load Build", "Error copying file(" + file + ") from build xbox!", MessageBoxButtons.OK); } } } progress.DialogKill(); } else { MOG_REPORT.ShowMessageBox("Make Linear Load Build", "There were no Linear Load files found on the Xbox Build machine(" + buildXbox + ")", MessageBoxButtons.OK); return; } // Check for user cancel Application.DoEvents(); if (bigProgress.DialogProcess()) { bigProgress.DialogKill(); return; } bigProgress.DialogUpdate(90, "Syncing to target Xbox..."); // Sync sinc = new guiPlatformSinc(mTargetXbox, mainForm.mAssetManager.GetTargetPath(), mainForm, userName, useDefault, false, false, false); sinc.mProjectSyncFile = "xbox.opt.ll.sync"; sinc.mUserSyncFile = ""; sinc.TargetConsoleSync(); } else { MOG_REPORT.ShowMessageBox("XBox Tools", string.Concat("This tool is missing, have you updated to the latest version?"), MessageBoxButtons.OK); } bigProgress.DialogUpdate(100, "Done!"); bigProgress.DialogKill(); }
private bool SyncFile(string fullFilename, string targetFile) { bool rc = false; // Check for special rules for this asset in the ReMap section if (!RemapString(fullFilename, ref targetFile)) { return(false); } // Get the file FileInfo file = new FileInfo(fullFilename); bool fileExists = false; if (mConsoleCopy && !mFileMapCreate) { fileExists = XboxUtils.FileExist(targetFile); } else if (!mConsoleCopy && !mFileMapCreate) { fileExists = DosUtils.FileExist(targetFile); } else { fileExists = false; } if (fileExists && !mGetFileCount && mConsoleCopy) { // Check to see if the sizes of the source and target are the same uint targetSize = XboxUtils.GetFileSize(targetFile); uint sourceSize = (uint)file.Length; if (targetSize != sourceSize) { fileExists = false; } } // Check if the target file exists // If asset is in our timestamp file, it means we have already copied it once. We need to check if there is a timestamp difference // But if the asset does not even exist on the xbox we should force a copy if (fileExists && (mTargetTimestamps.SectionExist("ASSETS") && mTargetTimestamps.KeyExist("ASSETS", file.FullName)) ) { // Get timestamp of target and source // Copy if they are not the same if (string.Compare(file.LastWriteTime.ToFileTime().ToString(), mTargetTimestamps.GetString("ASSETS", file.FullName)) != 0) { if (mGetFileCount) { mTotalFilesToCopy++; mPendingCopy.PutString("COPY_FILE", file.FullName, targetFile); mPendingCopy.Save(); } else { mProgress.DialogUpdate(mFileNumber++, string.Concat("Source: ", file.FullName, "\nTarget: ", targetFile)); Application.DoEvents(); if (mProgress.DialogProcess()) { return(false); } if (mConsoleCopy) { rc = XboxUtils.FileCopyVerify(file.FullName, targetFile, true); } else { rc = DosUtils.FileCopy(file.FullName, targetFile, true); } if (!rc) { mSummary.PutString("File.CopyError", file.FullName, targetFile); mSummary.Save(); // Check to see if the reason we failed is because we ran out of space // UInt64 freeSpace = XboxUtils.GetDiskFreeSpace(mSyncRoot); // if (freeSpace < (ulong)file.Length) // { // MOG_REPORT.ShowErrorMessageBox("Platform Sync: Out of space!", "There is insufficient space on " + mSyncRoot + " to copy " + file.FullName); // } } else { mSummary.PutString("File.Copied", file.FullName, targetFile); mSummary.Save(); mTargetTimestamps.PutString("ASSETS", file.FullName, file.LastWriteTime.ToFileTime().ToString()); mTargetTimestamps.Save(); } } } else { if (!mGetFileCount) { // This file is up to date mProgress.DialogUpdate(mFileNumber, string.Concat("FILE UP TO DATE! Skipping...\nSource: ", file.FullName)); Application.DoEvents(); // Check if the user cancels if (mProgress.DialogProcess()) { return(false); } } } } else { if (mGetFileCount) { mTotalFilesToCopy++; if (mFileMapCreate) { // When making a file map, put the target first then the source mPendingCopy.PutString("MAP", targetFile, file.FullName); } else { // When making a pending file, put the source first then target mPendingCopy.PutString("COPY_FILE", file.FullName, targetFile); } //mPendingCopy.PutString("COPY_FILE", file.FullName, targetFile); mPendingCopy.Save(); } else { mProgress.DialogUpdate(mFileNumber++, string.Concat("Source: ", file.FullName, "\nTarget: ", targetFile)); Application.DoEvents(); // Check if the user cancels if (mProgress.DialogProcess()) { return(false); } CreateTargetDirectoryPath(targetFile.Substring(0, targetFile.LastIndexOf("\\"))); // Sync the file to the platform try { if (mConsoleCopy) { rc = XboxUtils.FileCopyVerify(file.FullName, targetFile, true); } else { rc = DosUtils.FileCopy(file.FullName, targetFile, true); } //rc = XboxUtils.FileCopyVerify(file.FullName, targetFile, true); } catch (DllNotFoundException e) { MOG_REPORT.ShowMessageBox("DLL ERROR", e.ToString(), MessageBoxButtons.OK); return(false); } catch (EntryPointNotFoundException e) { MOG_REPORT.ShowMessageBox("DLL ERROR", e.ToString(), MessageBoxButtons.OK); return(false); } if (!rc) { // Error mSummary.PutString("File.CopyError", file.FullName, targetFile); mSummary.Save(); // Check to see if the reason we failed is because we ran out of space //UInt64 freeSpace = XboxUtils.GetDiskFreeSpace(mSyncRoot); //if (freeSpace < (ulong)file.Length) //{ // MOG_REPORT.ShowErrorMessageBox("Platform Sync: Out of space!", "There is insufficient space on " + mSyncRoot + " to copy " + file.FullName); //} } else { mSummary.PutString("File.Copied", file.FullName, targetFile); mSummary.Save(); mTargetTimestamps.PutString("ASSETS", file.FullName, file.LastWriteTime.ToFileTime().ToString()); mTargetTimestamps.Save(); } } } return(true); }
public void TargetConsoleRemoveSync() { // Build a list of exactly what should be on the xbox mGetFileCount = true; mTotalFilesToCopy = 0; bool success = true; string CopyFileMap = mSourcePath + "\\MOG\\platformSincMap." + mMog.GetActivePlatform().mPlatformName + ".info"; if (DosUtils.FileExist(CopyFileMap)) { if (!DosUtils.FileDelete(CopyFileMap)) { return; } } // Create the new map mPendingCopy = new MOG_Ini(CopyFileMap); InitializeFileMap(); mFileMapCreate = true; // Initialize our progress dialog mProgress = new CallbackDialogForm(); string message = "Preforming platform remove data Sync: \n" + " Project Sync file map:" + mProjectSyncFile + "\n" + " User Sync file map:" + mUserSyncFile + "\n"; mProgress.DialogInitialize("(" + mTargetConsole + ")Platform Remove Data Sync", message, ""); Application.DoEvents(); for (int i = 0; i < mPlatformSync.CountKeys("FileMap"); i++) { string sourcePath = FormatString(mPlatformSync.GetKeyNameByIndex("FileMap", i).ToLower()); string targetPath = sourcePath.Replace(mSourcePath, mSyncRoot); string filePattern = mPlatformSync.GetKeyByIndex("FileMap", i).ToLower(); success = SyncDirectories(sourcePath, filePattern, mSyncRoot); mProgress.DialogUpdate((i * 100) / mPlatformSync.CountKeys("FileMap"), sourcePath + "\n" + targetPath); Application.DoEvents(); // Create the needed directory on the xbox string newDirName = RemapDirectoryString(targetPath); if (mConsoleCopy) { if (!XboxUtils.FileExist(newDirName)) { mPendingCopy.PutSectionString("CREATE_DIR", newDirName); mPendingCopy.Save(); } } else { if (!DosUtils.FileExist(newDirName)) { mPendingCopy.PutSectionString("CREATE_DIR", newDirName); mPendingCopy.Save(); } } } if (mConsoleCopy) { // Logon to correct xbox XboxUtils.SetXboxName(mTargetConsole, false); } mProgress.DialogInitialize("Sync Remove", "Scanning console for non-needed assets", ""); ArrayList deletableAssets = new ArrayList(); // Verify the xbox for each of these files for (int j = 0; j < mPlatformSync.CountKeys("FileMap"); j++) { string sourcePath = FormatString(mPlatformSync.GetKeyNameByIndex("FileMap", j).ToLower()); string targetPath = sourcePath.Replace(mSourcePath, mSyncRoot); string walkFiles = XboxUtils.GetFiles(targetPath + "\\"); mProgress.DialogUpdate((j * 100) / mPlatformSync.CountKeys("FileMap"), sourcePath + "\n" + targetPath); Application.DoEvents(); if (walkFiles.Length != 0 && walkFiles.IndexOf(",") != -1) { string [] files = walkFiles.Split(",".ToCharArray()); for (int k = 0; k < files.Length; k++) { string targetFile = files[k]; if (Path.GetExtension(targetFile) != "") { // Check to see if this file exists in the map if (!mPendingCopy.KeyExist("MAP", targetFile)) { // Get the list of deletable assets deletableAssets.Add(targetFile); } } } } } mProgress.DialogKill(); mProgress = null; if (deletableAssets.Count != 0) { if (guiConfirmDialog.MessageBoxDialog("Console Remove Sync", "Is is OK to Delete the Following Assets?", deletableAssets, MessageBoxButtons.OKCancel) == DialogResult.OK) { // Delete the assets in the list from off the xbox foreach (string str in guiConfirmDialog.SelectedItems) { string [] parts = str.Split(",;".ToCharArray()); if (parts != null && parts.Length >= 2) { string assetDeleteName = parts[0]; XboxUtils.FileDelete(assetDeleteName); } } } } else { MOG_REPORT.ShowMessageBox("Sync Remove", "This target does not have any files that need to be deleted", MessageBoxButtons.OK); } }