private ListViewItem CreateListViewItemForFile(string localFile) { ListViewItem item = null; // Only put the asset in the list if it is actually a library asset if (MOG_ControllerLibrary.IsPathWithinLibrary(localFile)) { item = new ListViewItem(Path.GetFileName(localFile)); string classification = MOG_ControllerLibrary.ConstructLibraryClassificationFromPath(localFile); string localTimestamp = GetLocalFileTimestamp(localFile); string fullname = localFile; string status = "Unknown"; string extension = DosUtils.PathGetExtension(localFile); // Populate the item item.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(localFile); item.SubItems.Add(extension); // Extension item.SubItems.Add(classification); // Classification item.SubItems.Add(""); // User item.SubItems.Add(""); // Comment item.SubItems.Add(localTimestamp); // Local TimeStamp item.SubItems.Add(""); // Server Timestamp item.SubItems.Add(status); // Status item.SubItems.Add(fullname); // Fullname item.SubItems.Add(localFile); // LocalFile item.SubItems.Add(""); // RepositoryFile UpdateListViewItemColors(item, status); } return(item); }
private void BuildWindowsFileNode(TreeNode parentNode, string displayString, string fullFilename) { // Split up str into the path and filename string[] parts = displayString.Split("\\".ToCharArray()); TreeNode thisNode = FindNode(parentNode, parts[0]); if (thisNode == null) { string nodeText = parts[0]; // Check if this is the final layer? if (parts.Length == 1) { nodeText = displayString; } // Create a new node thisNode = new TreeNode(nodeText); thisNode.Checked = true; thisNode.Tag = fullFilename; // Check if this is the final item? if (parts.Length == 1) { // Add this to the bottom because it is the final node parentNode.Nodes.Add(thisNode); } else { // Insert this at the top because it is a directory parentNode.Nodes.Insert(0, thisNode); } try { // Select file icon thisNode.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(thisNode.FullPath); } catch (Exception e) { e.ToString(); } } // Check if we need to keep drilling? if (parts.Length > 1) { string remainingPath = displayString.Substring(parts[0].Length + 1); BuildWindowsFileNode(thisNode, remainingPath, fullFilename); } }
private int AppendSummary(string section, string comment, Color nodeColor) { // Get all the file copies if (mSummary.SectionExist(section)) { string[] keys = mSummary.GetSectionKeys(section); foreach (string key in keys) { // Get the asset/file information from the summary file string assetName = mSummary.GetString(section, key); string fileName = key; // Trim any starting '\' if (fileName != null && fileName.Length > 0) { fileName = fileName.TrimStart("\\".ToCharArray()); } try { string fullfilename = MOG_ControllerProject.GetCurrentSyncDataController().GetSyncDirectory() + "\\" + fileName; ListViewItem item = new ListViewItem(); item.Text = Path.GetFileName(fileName); item.ForeColor = nodeColor; FileInfo file = new FileInfo(fullfilename); item.SubItems.Add(file.LastWriteTime.ToShortDateString() + " " + file.LastWriteTime.ToShortTimeString()); item.SubItems.Add(comment); item.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(fullfilename); SummaryListView.Items.Add(item); } catch (Exception e) { MOG_Report.ReportMessage("Update Summary", e.Message, e.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.ERROR); } } return(mSummary.CountKeys(section)); } return(0); }
private void UpdateItem(ListViewItem item) { string status = ""; string username = ""; string comment = ""; string localTimestamp = ""; // Find our desired columns int statusIdx = FindColumn("Status"); int userIdx = FindColumn("User"); int commentIdx = FindColumn("Comment"); int localTimestampIdx = FindColumn("Local Timestamp"); int serverTimestampIdx = FindColumn("Server Timestamp"); int localFileIdx = FindColumn("LocalFile"); int repositoryFileIdx = FindColumn("RepositoryFile"); string repositoryFile = item.SubItems[repositoryFileIdx].Text; MOG_Filename repositoryAssetFilename = new MOG_Filename(repositoryFile); // Check if this file exist locally? string localFile = item.SubItems[localFileIdx].Text; if (localFile.Length != 0) { // Obtain the localFile info FileInfo fileInfo = new FileInfo(localFile); // Does this local file exist? if (fileInfo != null && fileInfo.Exists) { // Compare our local file's timestamp to the server's revision localTimestamp = MOG_Time.GetVersionTimestamp(fileInfo.LastWriteTime); if (localTimestamp == repositoryAssetFilename.GetVersionTimeStamp()) { // Indicate this item is synced and up-to-date status = "Up-to-date"; } else { // Indicate this item is synced status = "Out-of-date"; } } else { // Indicate this item is not synced status = "unSynced"; } } else { // Indicate this item is not synced status = "unSynced"; } // Check if this file exists in the repository? if (repositoryFile.Length != 0) { // Check the lock statusIdx of the asset MOG_Command sourceLock = MOG_ControllerProject.PersistentLock_Query(repositoryAssetFilename.GetAssetFullName()); if (sourceLock.IsCompleted() && sourceLock.GetCommand() != null) { MOG_Command lockHolder = sourceLock.GetCommand(); // Obtain the lock info item.ImageIndex = MogUtil_AssetIcons.GetLockedBinaryIcon(repositoryFile); username = lockHolder.GetUserName(); comment = lockHolder.GetDescription(); // Check if this is locked by me? if (username == MOG_ControllerProject.GetUserName()) { status = "CheckedOut"; } else { status = "Locked"; } } else { // Update this file's icon item.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(repositoryFile); } } // Update the item with the new information item.SubItems[statusIdx].Text = status; item.SubItems[userIdx].Text = username; item.SubItems[commentIdx].Text = comment; item.SubItems[localTimestampIdx].Text = MogUtils_StringVersion.VersionToString(localTimestamp); item.SubItems[serverTimestampIdx].Text = MogUtils_StringVersion.VersionToString(repositoryAssetFilename.GetVersionTimeStamp()); // Update the color for this locked item UpdateListViewItemColors(item, status); }
/// <summary> /// Update an existing ListView node for the asset manager inboxes /// </summary> /// <param name="pProperties"></param> /// <param name="nodeColor"></param> /// <returns></returns> public static void UpdateListViewItem(ListViewItem item, MOG_Filename asset, string status, MOG_Properties pProperties) { string date = ""; string size = ""; string creator = ""; string owner = ""; string group = ""; string target = ""; // Check if we have a properties? if (pProperties != null) { // If we have a valid gameDataController, set our platform scope if (MOG_ControllerProject.GetCurrentSyncDataController() != null) { // Set our current platform pProperties.SetScope(MOG_ControllerProject.GetCurrentSyncDataController().GetPlatformName()); } // Gather the following info from our properties date = MOG_Time.FormatTimestamp(pProperties.CreatedTime, ""); size = guiAssetController.FormatSize(pProperties.Size); creator = pProperties.Creator; owner = pProperties.Owner; group = pProperties.Group; // Check if this is a packaged asset? if (pProperties.IsPackagedAsset) { // Check if we have have any package assignments in our propeerties? ArrayList packages = pProperties.GetPackages(); if (packages.Count == 0) { // Indicate this is a packaged asset w/o any package assignments target = "Missing package assignment..."; } else if (packages.Count == 1) { MOG_Property package = packages[0] as MOG_Property; MOG_Filename packageName = new MOG_Filename(MOG_ControllerPackage.GetPackageName(package.mPropertyKey)); string packageGroupPath = MOG_ControllerPackage.GetPackageGroups(package.mPropertyKey); string displayString = MOG_ControllerPackage.CombinePackageAssignment(packageName.GetAssetLabel(), packageGroupPath, ""); target = "{Package} " + displayString + " in " + MOG_Filename.GetAdamlessClassification(packageName.GetAssetClassification()); } else { target = "{Package} " + packages.Count + " Assignments..."; } } else if (pProperties.SyncFiles) { // Get the formatted SyncTarget of this asset target = MOG_Tokens.GetFormattedString("{Workspace}\\" + pProperties.SyncTargetPath, asset, pProperties.GetPropertyList()); } } item.Text = asset.GetAssetLabel(); // Populate the item's SubItems // I tried for a long time to be smart here and use ColumnNameFind(thisListView.Columns, "Name") but // I kept running into walls because this function is used by a lot of workers outside of the ListView's thread. // So, I gave up and am just going to do it the ugly brute force way! YUCK!! item.SubItems[(int)AssetBoxColumns.NAME].Text = asset.GetAssetLabel(); item.SubItems[(int)AssetBoxColumns.CLASS].Text = asset.GetAssetClassification(); item.SubItems[(int)AssetBoxColumns.TARGETPATH].Text = target; item.SubItems[(int)AssetBoxColumns.DATE].Text = date; item.SubItems[(int)AssetBoxColumns.SIZE].Text = size; item.SubItems[(int)AssetBoxColumns.PLATFORM].Text = asset.GetAssetPlatform(); item.SubItems[(int)AssetBoxColumns.STATE].Text = status; item.SubItems[(int)AssetBoxColumns.CREATOR].Text = creator; item.SubItems[(int)AssetBoxColumns.RESPPARTY].Text = owner; item.SubItems[(int)AssetBoxColumns.OPTIONS].Text = ""; item.SubItems[(int)AssetBoxColumns.FULLNAME].Text = asset.GetEncodedFilename(); item.SubItems[(int)AssetBoxColumns.BOX].Text = asset.GetBoxName(); item.SubItems[(int)AssetBoxColumns.GROUP].Text = group; // Set the item's Icons item.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(asset.GetEncodedFilename(), pProperties); if (MogMainForm.MainApp != null && MogMainForm.MainApp.mAssetManager != null) { // mAssetStatus.GetStatusInfo() is sort of a black sheep and should maybe become static item.StateImageIndex = MogMainForm.MainApp.mAssetManager.mAssetStatus.GetStatusInfo(status).IconIndex; } // Set the item's color item.ForeColor = MOG_AssetStatus.GetColor(status); // Check if this is a local item that has been blessed? if (asset.IsLocal() && string.Compare(status, MOG_AssetStatus.GetText(MOG_AssetStatusType.Blessed), true) == 0) { // Mark local blessed items with light gray item.ForeColor = Color.LightGray; } }
private void DialogInitialize_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <Object> args = e.Argument as List <Object>; string parentPath = args[0] as string; ArrayList assets = args[1] as ArrayList; ArrayList assetLabels = args[2] as ArrayList; TreeNode parentNode = null; for (int counter = 0; counter < assets.Count; counter++) { string rawString = assets[counter] as string; string labelString = (assetLabels != null) ? assetLabels[counter] as string : ""; worker.ReportProgress(counter * 100 / assets.Count); // Determin if we should use the label or the str string displayString = (labelString.Length > 0) ? labelString : rawString; // Check if this is an official MOG_Filename? and // Make sure it contains no path! MOG_Filename filename = new MOG_Filename(displayString); if (filename.GetFilenameType() != MOG_FILENAME_TYPE.MOG_FILENAME_Unknown && filename.GetPath().Length == 0) { if (ConfirmTreeView.ImageList != MogUtil_AssetIcons.Images) { ConfirmTreeView.ImageList = MogUtil_AssetIcons.Images; } // Build the node BuildMogFilenameNode(filename, rawString, labelString); } // Check if this resembles a path? else if (displayString.Contains("\\")) { // Is this the first node? if (ConfirmTreeView.Nodes.Count == 0) { // Check if we are missing a parentPath? if (parentPath.Length == 0) { // Use the root of the file as our parentPath parentPath = displayString.Substring(0, displayString.IndexOf("\\")); } // Create the start node parentNode = ConfirmTreeView.Nodes.Add(parentPath); parentNode.Checked = true; try { // Select file icon parentNode.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(parentNode.FullPath); } catch (Exception ex) { ex.ToString(); } } // Figure out what...if any...remainingPath string remainingPath = ""; if (displayString.StartsWith(parentPath, StringComparison.CurrentCultureIgnoreCase)) { remainingPath = displayString.Substring(parentPath.Length).Trim("\\".ToCharArray()); } // Build the Node path BuildWindowsFileNode(parentNode, remainingPath, rawString); } else { // Check if we have a parentNode? if (parentNode != null) { // Just add the basic node TreeNode thisNode = new TreeNode(displayString); thisNode.Checked = true; parentNode.Nodes.Add(thisNode); } } } }
/// <summary> /// Mother of all ImageIndex getting, not meant to be used outside this class /// </summary> private int GetImageIndex(string filename, bool searchFileSystem, bool isClassification) { // If we are a Classification, return our GetClassIconIndex if (isClassification) { return(MogUtil_AssetIcons.GetClassIconIndex(filename)); } int iconIndex = 0; // If we need to search the FileSystem, do so... if (searchFileSystem) { iconIndex = MogUtil_AssetIcons.GetFileIconIndex(filename); // If we got an iconIndex other than 0, return our value... if (iconIndex != 0) { return(iconIndex); } // Else, continue processing } // Try getting our index through GetAssetIconIndex iconIndex = MogUtil_AssetIcons.GetAssetIconIndex(filename); // If we got an iconIndex other than 0, return... if (iconIndex != 0) { return(iconIndex); } // Look for our index using our MOG_Filename and MOG_Properties MOG_Filename realFile = new MOG_Filename(filename); MOG_Properties properties = null; // If we have an Asset, get its properties if (realFile.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { properties = new MOG_Properties(realFile); // So long as we got a properties... if (properties != null) { iconIndex = MogUtil_AssetIcons.GetAssetIconIndex(properties.AssetIcon); // If we have a valid iconIndex, return it if (iconIndex != 0) { return(iconIndex); } // Else if Package, return our default Package icon else if (properties.IsPackage) { return(MogUtil_AssetIcons.GetClassIconIndex(Package_ImageText)); } // Else, return our default Asset icon else { return(MogUtil_AssetIcons.GetClassIconIndex(Asset_ImageText)); } } } // If after all our work, we still didn't find an icon (and we know we're not a // Classification) throw an exception to the programmer if (iconIndex == 0) { // KLK - There is no need to thow if the icon could not be located. Just return a bogus icon //throw new Exception(ToString() + ": Error with TreeNode.ImageIndex on a non-Classification.\r\n" // + "ImageIndex should not be 0 for a non-Classification"); } return(iconIndex); }