Ejemplo n.º 1
0
        static public bool AddAssetToWorkspaces(MOG_Filename assetFilename, bool userInitiated, BackgroundWorker worker)
        {
            bool bFailed = false;

            // Open the asset now to save time later so it doesn't need to be opened for each workspace
            MOG_ControllerAsset asset = MOG_ControllerAsset.OpenAsset(assetFilename);

            if (asset != null)
            {
                try
                {
                    // Walk through all of our workspaces
                    foreach (MOG_ControllerSyncData workspace in mWorkspaces.Values)
                    {
                        bool bAddAsset = false;

                        // Check if this workspace is active?
                        if (workspace.IsAlwaysActive())
                        {
                            bAddAsset = true;
                        }
                        // Imported asset has special logic
                        else if (asset.GetProperties().Status == MOG_AssetStatus.GetText(MOG_AssetStatusType.Imported))
                        {
                            // Check if this asset originated from within this workspace?  (special case added for SmartBomb so editor will always update the workspace of an object sent from the editor)
                            if (DosUtils.PathIsWithinPath(workspace.GetSyncDirectory(), asset.GetProperties().SourcePath))
                            {
                                bAddAsset = true;
                            }
                            // Check if the user actually initiated this event?
                            else if (userInitiated &&
                                     workspace == MOG_ControllerProject.GetCurrentSyncDataController())
                            {
                                bAddAsset = true;
                            }
                        }
                        // All other assets should simply go into the current
                        else if (workspace == MOG_ControllerProject.GetCurrentSyncDataController())
                        {
                            bAddAsset = true;
                        }

                        // Should this asset be added?
                        if (bAddAsset)
                        {
                            // Decide if the user wants to be notified about the asset's update
                            bool bInformUser = userInitiated;
                            // Check if no worker was specified?  or
                            // Check if this isn't the active workspace?
                            if (worker == null ||
                                workspace != MOG_ControllerProject.GetCurrentSyncDataController())
                            {
                                // Don't bother the user about any problems
                                bInformUser = false;
                            }

                            // Check if we can add this asset to the local workspace?
                            if (workspace.CanAddAssetToLocalWorkspace(asset, bInformUser))
                            {
                                // Check if this asset comming from an inbox?   and
                                // Check if this asset comming from our inbox?   and
                                // Check if this asset's current state is 'Imported'  and
                                // Check if this asset originated from this workspace?
                                // Finally, Make sure this wasn't user initiated?
                                if (assetFilename.IsWithinInboxes() &&
                                    string.Compare(assetFilename.GetUserName(), MOG_ControllerProject.GetUserName(), true) == 0 &&
                                    string.Compare(asset.GetProperties().Status, MOG_AssetStatus.GetText(MOG_AssetStatusType.Imported), true) == 0 &&
                                    MOG_Filename.IsWithinPath(workspace.GetSyncDirectory(), asset.GetProperties().SourcePath) &&
                                    !userInitiated)
                                {
                                    // Looks like we can proceed to import
                                    if (!workspace.AddAssetToLocalUpdatedTray(asset, worker))
                                    {
                                        bFailed = true;
                                    }

                                    // Continue on to the next asset
                                    continue;
                                }

                                // Proceed to add the asset to this workspace
                                if (!workspace.AddAssetToLocalWorkspace(asset, worker))
                                {
                                    bFailed = true;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    asset.Close();
                }
            }
            else
            {
                bFailed = true;
            }

            if (!bFailed)
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Fetch the next set of files and folders for this parent folder
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="fullPath"></param>
        /// <param name="targetGameData"></param>
        private void VirtualExpand(TreeNode parent, string fullPath, string workspaceDirectory)
        {
            try
            {
                // If we have a gameData target we need to remove it from our path prepatory to the Dictionary lookup of the children of this folder
                if (DosUtils.PathIsWithinPath(workspaceDirectory, fullPath))
                {
                    // Also remove any begininng backslashes
                    fullPath = DosUtils.PathMakeRelativePath(workspaceDirectory, fullPath);
                }

                HybridDictionary dic = mSyncTargetFiles.GetFiles(fullPath);
                if (dic != null)
                {
                    // Search our btree for the children of this folder
                    IDictionaryEnumerator file = dic.GetEnumerator();

                    // Now itterate through those children
                    while (file.MoveNext())
                    {
                        string fullDirectoryName = "";
                        // we now need to reconstruct the full path to this file or folder
                        if (fullPath.Length == 0)
                        {
                            fullDirectoryName = workspaceDirectory + "\\" + file.Key;
                        }
                        else
                        {
                            fullDirectoryName = workspaceDirectory + "\\" + fullPath + "\\" + file.Key;
                        }

                        DirectorySetInfo fileInfo = (DirectorySetInfo)file.Value;

                        // Create the node
                        TreeNode newNode = CreateTreeNodeFullPath(GameDataTreeView, parent, workspaceDirectory, "\\", file.Key as string, fullDirectoryName, fileInfo, 0, 0, 0, 0, true);

                        // If this is a newly created node and it is a folder, we assume it has children and create a black node beneath it
                        if (newNode != null && newNode.Nodes.Count == 0)
                        {
                            guiAssetTreeTag info           = (guiAssetTreeTag)newNode.Tag;
                            string          relationalPath = "";

                            // Get a relational path to this folder
                            if (fullPath.Length == 0)
                            {
                                relationalPath = file.Key as string;
                            }
                            else
                            {
                                relationalPath = fullPath + "\\" + file.Key;
                            }

                            // If this file is a folder and has children, create a place holder 'blank'
                            if (info != null && info.TagType == guiAssetTreeTag.TREE_FOCUS.FOLDER && mSyncTargetFiles.HasFolderChildren(relationalPath, false))
                            {
                                newNode.Nodes.Add("BLANK");
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }