示例#1
0
        protected virtual void LoadDo(ProgressCallback callback = null)
        {
            bool reportProgress = callback != null;
            var  files          = WorkDir.EnumerateFiles("*.tpac", SearchOption.TopDirectoryOnly).ToList();
            var  packageCount   = files.Count;
            int  i = 0;

            foreach (var file in files)
            {
                if (reportProgress)
                {
                    callback(i++, packageCount, file.Name, false);
                }
                var package = new AssetPackage(file.FullName);
                package.IsGuidLocked = true;
                _loadedPackages.Add(package);
                _packageLookup[package.Guid] = package;
                foreach (var assetItem in package.Items)
                {
                    _assetLookup[assetItem.Guid] = assetItem;
                    _loadedAssets.Add(assetItem);
                }
            }
            if (reportProgress)
            {
                callback(packageCount, packageCount, String.Empty, true);
            }
        }
示例#2
0
        [Obsolete]         // WIP. removing assert lookup is not finished yet
        public bool RemovePackage(Guid guid, out AssetPackage removedPackage)
        {
            if (_packageLookup.TryGetValue(guid, out removedPackage))
            {
                _packageLookup.Remove(guid);
                _loadedPackages.Remove(removedPackage);
                return(true);
            }

            return(false);
        }
示例#3
0
 [Obsolete]         // WIP. adding assert lookup is not finished yet
 public void AddPackage(AssetPackage package)
 {
     if (package.IsGuidLocked)
     {
         throw new ArgumentException("The guid of adding package is locked. That is unexpected. " +
                                     "It can be caused by adding an existed package to its owner manager", "package");
     }
     if (_packageLookup.ContainsKey(package.Guid))
     {
         throw new ArgumentException("The guid is already occupied: " + package.Guid, "package");
     }
     if (package.Guid == Guid.Empty)
     {
         throw new ArgumentException("The guid cannot be empty", "package");
     }
     _loadedPackages.Add(package);
     _packageLookup[package.Guid] = package;
     package.IsGuidLocked         = true;
 }
示例#4
0
        protected virtual void LoadDo(ProgressCallback callback = null)
        {
            bool            reportProgress = callback != null;
            List <FileInfo> files          = null;

#if !NETSTANDARD1_3
            Thread thread = new Thread(() =>
            {
                try
                {
                    var fs = WorkDir.EnumerateFiles("*.tpac", SearchOption.AllDirectories).ToList();
                    files  = fs;
                }
                catch (ThreadAbortException)
                {
                }
            });
            thread.Name         = "Tpac Searcher";
            thread.IsBackground = true;
            thread.Start();
            while (true)
            {
                if (reportProgress && !callback(-1, -1, String.Empty, false))
                {
                    if (thread.ThreadState != ThreadState.Stopped)
                    {
                        thread.Abort();
                    }
                    InterruptLoading();
                    return;
                }
                if (files != null)
                {
                    break;
                }
                Thread.Sleep(100);
                Thread.Yield();
            }
#else
            files = WorkDir.EnumerateFiles("*.tpac", SearchOption.AllDirectories).ToList();
#endif

            var packageCount = files.Count;
            int i            = 0;
            foreach (var file in files)
            {
                if (reportProgress && !callback(i++, packageCount, file.Name, false))
                {
                    InterruptLoading();
                    return;
                }
                var package = new AssetPackage(file.FullName);
                package.IsGuidLocked = true;
                _loadedPackages.Add(package);
                _packageLookup[package.Guid] = package;
                foreach (var assetItem in package.Items)
                {
                    _assetLookup[assetItem.Guid] = assetItem;
                    _loadedAssets.Add(assetItem);
                }
            }

            if (reportProgress && !callback(packageCount, packageCount, String.Empty, true))
            {
                InterruptLoading();
                return;
            }
        }