/// <summary> /// Refresh an assets status from a ViewUpdate Command /// </summary> public void RefreshBox(MOG_Filename add, MOG_Filename del, MOG_Command command) { lock (mAssetManager) { ListView currentViewAdd = mAssetManager.IsolateListView(add.GetBoxName(), add.GetFilenameType(), add.GetUserName()); ListView currentViewDel = mAssetManager.IsolateListView(del.GetBoxName(), del.GetFilenameType(), del.GetUserName()); // Don't continue if we don't have a valid add and del box if ((currentViewAdd == null) && (currentViewDel == null)) { return; } // Begin the update if (currentViewAdd != null) { currentViewAdd.BeginUpdate(); } if (currentViewDel != null) { currentViewDel.BeginUpdate(); } string status = command.GetDescription(); mAssetManager.mainForm.mSoundManager.PlayStatusSound("AssetEvents", status); try { // Obtain the properties from the command MOG_Properties pProperties = null; string[] commandProps = command.GetVeriables().Split("$".ToCharArray()); if (commandProps != null) { ArrayList realProps = new ArrayList(); // Convert the commandProps into a list of real Properties for (int i = 0; i < commandProps.Length; i++) { // Confirm this appears to be a valid prop? if (commandProps[i].StartsWith("[")) { MOG_Property commandProp = new MOG_Property(commandProps[i]); // Make sure the property was initialized correctly? if (commandProp.mSection.Length > 0 && commandProp.mKey.Length > 0) { // Add this realProp realProps.Add(commandProp); } } } // Construct the pProperties from the realProps pProperties = new MOG_Properties(realProps); // If we have a valid gameDataController, set our platform scope if (MOG_ControllerProject.GetCurrentSyncDataController() != null) { pProperties.SetScope(MOG_ControllerProject.GetCurrentSyncDataController().GetPlatformName()); } } // Check if we are just updating an item in the same list? if (currentViewAdd == currentViewDel) { // Check to see if this item already exists? int targetIndex = mAssetManager.ListViewItemFindFullItem(del, currentViewDel); int sourceIndex = mAssetManager.ListViewItemFindFullItem(add, currentViewAdd); if (sourceIndex != -1) { // Update the existing item ListViewItem item = currentViewAdd.Items[sourceIndex]; guiAssetManager.UpdateListViewItem(item, add, status, pProperties); // If there was also a target index, we need to delete it because the source became the target. if (targetIndex != -1 && targetIndex != sourceIndex) { ListViewItem removeItem = currentViewAdd.Items[targetIndex]; // Make sure to clear our stateImage index which will clear the checked state before we attempt to remove the node or we will throw removeItem.StateImageIndex = 0; currentViewAdd.Items.Remove(removeItem); } } // Special case when we are dealing with a renamed file else if (targetIndex != -1 && sourceIndex == -1) { // Get the old item ListViewItem item = currentViewDel.Items[targetIndex]; // Update it to the new renamed item guiAssetManager.UpdateListViewItem(item, add, status, pProperties); } else { // Add a new item CreateListViewItem(currentViewAdd, add, status, pProperties); // Make sure we always keep our tab's text up-to-date mAssetManager.UpdateAssetManagerTabText(add); } } else { // Looks like we may need to do both the add and the remove // Check if we have the currentViewDel? if (currentViewDel != null) { int index = mAssetManager.ListViewItemFindFullItem(del, currentViewDel); if (index != -1) { ListViewItem item = currentViewDel.Items[index]; // Make sure to clear our stateImage index which will clear the checked state before we attempt to remove the node or we will throw item.StateImageIndex = 0; // Remove the item from the list currentViewDel.Items.Remove(item); // Make sure we always keep our tab's text up-to-date mAssetManager.UpdateAssetManagerTabText(del); } } // Check if we have the currentViewAdd? if (currentViewAdd != null) { // Check to see if this item already exists? int sourceIndex = mAssetManager.ListViewItemFindFullItem(add, currentViewAdd); if (sourceIndex != -1) { // Update the existing item ListViewItem item = currentViewAdd.Items[sourceIndex]; guiAssetManager.UpdateListViewItem(item, add, status, pProperties); } else { // Add a new item CreateListViewItem(currentViewAdd, add, status, pProperties); // Make sure we always keep our tab's text up-to-date mAssetManager.UpdateAssetManagerTabText(add); } } } } catch (Exception ex) { MOG_Report.ReportSilent("RefreshBox", ex.Message, ex.StackTrace); } // End the update if (currentViewAdd != null) { currentViewAdd.EndUpdate(); } if (currentViewDel != null) { currentViewDel.EndUpdate(); } } }