private void Restore(string projName, string iniFilename) { // make sure iniFilename points to valid file if (File.Exists(iniFilename)) { // make sure directory exists if (Directory.Exists(MOG_ControllerSystem.GetSystemDeletedProjectsPath() + "\\" + projName)) { if (DosUtils.DirectoryExistFast(MOG_ControllerSystem.GetSystemProjectsPath() + "\\" + projName)) { // A project of this name already exists MOG_Prompt.PromptMessage("Project Name Conflict", "Projects cannot be restored over the top of another active project."); return; } List <string> args = new List <string>(); args.Add(projName); args.Add(iniFilename); string message = "Please wait while MOG restores deleted project.\n" + " PROJECT: " + projName; ProgressDialog progress = new ProgressDialog("Restoring project", message, Restore_Worker, args, false); progress.ShowDialog(); } } }
private void LoadIniFile(string iniFilePath) { if (!File.Exists(iniFilePath)) { return; } // setup list view and ini reader this.lvRemovedProjects.Items.Clear(); MOG_Ini ini = new MOG_Ini(iniFilePath); // Make sure the section exists? if (ini.SectionExist("Projects.Deleted")) { // for each "deleted" project listed for (int i = 0; i < ini.CountKeys("Projects.Deleted"); i++) { string projName = ini.GetKeyNameByIndexSLOW("Projects.Deleted", i); // Check if the deleted project's directory is missing? if (!DosUtils.DirectoryExistFast(MOG_ControllerSystem.GetSystemDeletedProjectsPath() + "\\" + projName)) { // Auto clean this deleted project from the ini ini.RemoveSection(projName + ".Deleted"); ini.RemoveString("projects.deleted", projName); continue; } ListViewItem item = new ListViewItem(); item.Text = projName; // item.Tag = new RemovedProjectInfo( configFile ); this.lvRemovedProjects.Items.Add(item); } } ini.Close(); }
public void Populate(string classification) { CurrentClassification = classification; mCurrentClassificationProperties = new MOG_Properties(CurrentClassification); // For speed purposes, create 3 HybridDictionary lists // Populate the files that exist on the local hardrive string drivePath = Path.Combine(MOG_ControllerLibrary.GetWorkingDirectory(), MOG_Filename.GetClassificationPath(classification)); string[] files = new string[] { }; if (DosUtils.DirectoryExistFast(drivePath)) { files = Directory.GetFiles(drivePath); } HybridDictionary filesOnDisk = new HybridDictionary(); foreach (string file in files) { filesOnDisk[Path.GetFileName(file)] = file; } // Populate the assets that exist in MOG ArrayList assets = MOG_ControllerAsset.GetAssetsByClassification(classification); HybridDictionary assetsInMOG = new HybridDictionary(); foreach (MOG_Filename asset in assets) { assetsInMOG[asset.GetAssetLabel()] = asset; } // Create a master list HybridDictionary masterList = new HybridDictionary(); foreach (string file in filesOnDisk.Values) { masterList[Path.GetFileName(file)] = Path.GetFileName(file); } foreach (MOG_Filename asset in assetsInMOG.Values) { masterList[asset.GetAssetLabel()] = asset.GetAssetLabel(); } // Rebuild our LibraryListView LibraryListView.BeginUpdate(); mLibrarySortManager.SortEnabled = false; LibraryListView.Items.Clear(); foreach (string file in masterList.Keys) { // Check if this file is in MOG? if (assetsInMOG.Contains(file)) { MOG_Filename asset = assetsInMOG[file] as MOG_Filename; // Create the ListView item for this asset ListViewItem item = CreateListViewItemForAsset(asset); LibraryListView.Items.Add(item); } else { string fullFilename = filesOnDisk[file] as string; bool bIsValid = true; // Check the classification's inclusion filter. if (mCurrentClassificationProperties.FilterInclusions.Length > 0) { MOG.FilePattern inclusions = new MOG.FilePattern(mCurrentClassificationProperties.FilterInclusions); if (inclusions.IsFilePatternMatch(Path.GetFileName(fullFilename)) == false) { bIsValid = false; } } // Check the classification's exclusion filter. if (mCurrentClassificationProperties.FilterExclusions.Length > 0) { MOG.FilePattern exclusions = new MOG.FilePattern(mCurrentClassificationProperties.FilterExclusions); if (exclusions.IsFilePatternMatch(Path.GetFileName(fullFilename)) == true) { bIsValid = false; } } // Check if we determined this to be a valid file to show? if (bIsValid) { ListViewItem item = CreateListViewItemForFile(fullFilename); UpdateListViewItemColors(item, "Unknown"); LibraryListView.Items.Add(item); } } } mLibrarySortManager.SortEnabled = true; LibraryListView.EndUpdate(); // Check if we have a mLastTopItem specified? if (mLastTopItem.Length > 0) { LibraryListView.TopItem = LibraryListView.FindItemWithText(mLastTopItem); mLastTopItem = ""; } }
private static void ImportPrevious_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> args = e.Argument as List <object>; bool looseMatching = (bool)args[0]; string[] sourceFullNames = (args[1]) as string[]; //string[] sourceFullNames = e.Argument as string[]; mInvalidAssetNames.Clear(); mNewAssetNames.Clear(); mNewAssetProperties.Clear(); // Check if asset has been previously imported into the system for (int i = 0; i < sourceFullNames.Length && !worker.CancellationPending; i++) { string sourceFullName = sourceFullNames[i]; ArrayList previousSourceFiles = new ArrayList(); string message = "Importing:\n" + " " + Path.GetDirectoryName(sourceFullName) + "\n" + " " + Path.GetFileName(sourceFullName); worker.ReportProgress(i * 100 / sourceFullNames.Length, message); // Check if this is a directory? if (DosUtils.DirectoryExistFast(sourceFullName)) { // Obtain the list of contained files ArrayList containedFiles = DosUtils.FileGetRecursiveList(sourceFullName, "*.*"); if (containedFiles != null) { // Map these filenames to all the possible assetnames previousSourceFiles = MOG_ControllerProject.MapFilenamesToAssetNames(containedFiles, MOG_ControllerProject.GetPlatformName(), null); } } else { // Map this filename to all possible assetnames previousSourceFiles = MOG_ControllerProject.MapFilenameToAssetName(sourceFullName, MOG_ControllerProject.GetPlatformName(), MOG_ControllerProject.GetWorkspaceDirectory()); } // Are we loose matching? if (looseMatching) { // Did we get back only 2 files if (previousSourceFiles.Count == 2) { // Is the second one a blank? MOG_Filename file = previousSourceFiles[1] as MOG_Filename; if (file.GetFullFilename().Length == 0) { // Then remove it! previousSourceFiles.RemoveAt(1); } } } if (previousSourceFiles.Count == 1) { MOG_Filename previousFile = previousSourceFiles[0] as MOG_Filename; if (MogMainForm.MainApp.AssetManagerAutoImportCheckBox.Checked) { // Create the correct controller MOG_ControllerAsset.CreateAsset(sourceFullName, previousFile.GetEncodedFilename(), false); } else { // Create a new invalid name ImportFile invalidName = new ImportFile(sourceFullName); // Add all possible matches to this name foreach (MOG_Filename potentialMatch in previousSourceFiles) { // Make sure we have a valid match? if (potentialMatch != null && potentialMatch.GetOriginalFilename().Length > 0) { invalidName.mPotentialFileMatches.Add(potentialMatch); } } // Add to our invalidNames array mInvalidAssetNames.Add(invalidName); } } else { // Create a new invalid name ImportFile invalidName = new ImportFile(sourceFullName); // Add all possible matches to this name foreach (MOG_Filename potentialMatch in previousSourceFiles) { // Make sure we have a valid match? if (potentialMatch != null && potentialMatch.GetOriginalFilename().Length > 0) { invalidName.mPotentialFileMatches.Add(potentialMatch); } } // Add to our invalidNames array mInvalidAssetNames.Add(invalidName); } } }
private static void ImportAsOne_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> args = e.Argument as List <object>; bool looseFileMatching = (bool)args[0]; string[] sourceFilenames = (string[])args[1]; HybridDictionary exactAssetNames = new HybridDictionary(); HybridDictionary looseAssetNames = new HybridDictionary(); for (int i = 0; i < sourceFilenames.Length && !worker.CancellationPending; i++) { string filename = sourceFilenames[i]; ArrayList assetNames = new ArrayList(); string message = "Mapping:\n" + " " + Path.GetDirectoryName(filename) + "\n" + " " + Path.GetFileName(filename); worker.ReportProgress(i * 100 / sourceFilenames.Length, message); if (DosUtils.DirectoryExistFast(filename)) { // Obtain the list of contained files ArrayList containedFiles = DosUtils.FileGetRecursiveList(filename, "*.*"); if (containedFiles != null) { // Map these filenames to all the possible assetnames assetNames = MOG_ControllerProject.MapFilenamesToAssetNames(containedFiles, "", worker); } } else { // Map this filename to all possible assetnames assetNames = MOG_ControllerProject.MapFilenameToAssetName(filename, "", ""); } // Check if we found some assetNames? if (assetNames != null) { // Check if we are allowing loose matches? and // Check if this is a possible loose match? if (looseFileMatching && assetNames.Count == 2) { // Check if this is a blank? MOG_Filename assetName = assetNames[1] as MOG_Filename; if (assetName.GetFullFilename().Length == 0) { // Turn this into an exact match assetNames.RemoveAt(1); } } // Check if we found an exact match? if (assetNames.Count == 1) { // Add this to our list of exactAssetNames if we haven't already found it MOG_Filename assetName = assetNames[0] as MOG_Filename; if (!exactAssetNames.Contains(assetName.GetAssetFullName())) { exactAssetNames[assetName.GetAssetFullName()] = assetName; } } else { // Add all of the assetNames foreach (MOG_Filename assetName in assetNames) { // Check if this is a blank? if (assetName.GetFullFilename().Length == 0) { continue; } // Add this to our list of looseAssetNames if we haven't already found it if (!looseAssetNames.Contains(assetName.GetAssetFullName())) { looseAssetNames[assetName.GetAssetFullName()] = assetName; } } } } } // Check if we have any exact matches? if (exactAssetNames.Count > 0) { e.Result = new ArrayList(exactAssetNames.Values); } else { // Check if are allowing loose matching? if (looseFileMatching) { e.Result = new ArrayList(looseAssetNames.Values); } else { // Add back on the empty entry if it is needed if (looseAssetNames.Count == 1) { looseAssetNames[""] = new MOG_Filename(""); } // Return our list of foundAssets e.Result = new ArrayList(looseAssetNames.Values); } } }
// --------------------------------------------------- // performs purge - if purge scope is overriden, returns false; otherwise performs purge and returns true public bool ExecutePurge(PurgeCommand cmd) { if (!DosUtils.DirectoryExistFast(this.trashPath)) { //MessageBox.Show("Rejected purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\n because dir does not exist"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Rejected purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } because the specified directory does not exist"); } return(false); } if (cmd.Type != PurgeCommandType.FORCE) { if (cmd.Scope == PurgeCommandScope.GLOBAL && this.overridesGlobal) { //MessageBox.Show("Rejected purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\n because it overrides global commands"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Rejected purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } because it overrides global commands"); } return(false); // don't purge if we override global commands } if (cmd.Scope == PurgeCommandScope.PROJECT && this.overridesProject) { //MessageBox.Show("Rejected purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\n because it overrides project commands"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Rejected purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } because it overrides project commands"); } return(false); // don't purge if we override project commands } } // execute purge if (cmd.Type == PurgeCommandType.FORCE || cmd.Type == PurgeCommandType.INTERVAL) { try { Directory.Delete(this.trashPath, true); Directory.CreateDirectory(this.trashPath); this.lastPurged = DateTime.Now; //MessageBox.Show("Purged \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString(), "Purged"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Purged '" + this.trashPath + "' from command { " + cmd.ToString() + " }"); } } catch (Exception e) { //MessageBox.Show("Failed purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString() + " due to an exception:\n\n" + e.Message + "\n" + e.StackTrace, "Exception"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Failed purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } due to an exception:\n\n" + e.Message + "\n" + e.StackTrace); } } } else if (cmd.Type == PurgeCommandType.AGE) { ArrayList filelist = DeleteFilesByAge(this.trashPath, cmd.DayInterval, cmd.HourInterval, cmd.MinInterval, true); //string msg = ""; //foreach (string file in filelist) // msg += "\t" + file + "\n"; //MessageBox.Show("Age Purge of " + this.trashPath + " resulted in the following actions:\n\n" + msg); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Age-purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } resulted in the following actions:"); foreach (string file in filelist) { Utils.AppendLineToFile(this.logFilename, "\t\t\t\t" + file); } } } else if (cmd.Type == PurgeCommandType.MEGS) { if (DirSizeInMegs(this.trashPath) > (float)cmd.MegsLimit) { // purge it baby try { Directory.Delete(this.trashPath, true); Directory.CreateDirectory(this.trashPath); this.lastPurged = DateTime.Now; //MessageBox.Show("Purged (MEGS) \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString(), "Purged"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Megs-purged '" + this.trashPath + "' from command { " + cmd.ToString() + " }"); } } catch (Exception e) { //MessageBox.Show("Failed purge (MEGS) of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString() + " due to an exception:\n\n" + e.Message + "\n" + e.StackTrace, "Exception"); if (this.logActions) { Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Failed megs-purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } due to an exception:\n\n" + e.Message + "\n" + e.StackTrace); } } } } return(true); }