예제 #1
0
 private void ReleaseUser(IPackageUser user)
 {
     Users.Remove(user);
     if (Users.Count == 0)
     {
         noLongerOpenInTools?.Invoke(this);
     }
     user.ReleaseUse();
 }
예제 #2
0
        public static IMEPackage OpenME1Package(string pathToFile, IPackageUser user = null, bool forceLoadFromDisk = false)
        {
            IMEPackage pck = OpenMEPackage(pathToFile, user, forceLoadFromDisk);

            if (pck.Game == MEGame.ME1)
            {
                return(pck);
            }

            pck.Release(user);
            throw new FormatException("Not an ME1 package file.");
        }
예제 #3
0
 public void RegisterTool(IPackageUser user)
 {
     // DEBUGGING MEMORY LEAK CODE
     //Debug.WriteLine($"{FilePath} RefCount incrementing from {RefCount} to {RefCount + 1} due to RegisterTool()");
     RefCount++;
     Users.Add(user);
     user.RegisterClosed(() =>
     {
         ReleaseUser(user);
         Dispose();
     });
 }
예제 #4
0
 /// <summary>
 /// Opens an already open package, registering it for use in a tool.
 /// </summary>
 /// <param name="package"></param>
 /// <param name="user"></param>
 /// <returns></returns>
 public static IMEPackage OpenMEPackage(IMEPackage package, IPackageUser user = null)
 {
     if (user != null)
     {
         package.RegisterTool(user);
         addToPackagesInTools(package);
     }
     else
     {
         package.RegisterUse();
     }
     return(package);
 }
예제 #5
0
 public void Release(IPackageUser user = null)
 {
     if (user != null)
     {
         user = Users.FirstOrDefault(x => x == user);
         if (user != null)
         {
             ReleaseUser(user);
         }
         else
         {
             Debug.WriteLine("Releasing package that isn't in use by any user");
         }
     }
     Dispose();
 }
예제 #6
0
        /// <summary>
        /// Opens a Mass Effect package file. By default, this call will attempt to return an existing open (non-disposed) package at the same path if it is opened twice. Use the forceLoadFromDisk parameter to ignore this behavior.
        /// </summary>
        /// <param name="pathToFile">Path to the file to open</param>
        /// <param name="user">????</param>
        /// <param name="forceLoadFromDisk">If the package being opened should skip the shared package cache and forcibly load from disk. </param>
        /// <returns></returns>
        public static IMEPackage OpenMEPackage(string pathToFile, IPackageUser user = null, bool forceLoadFromDisk = false, bool quickLoad = false)
        {
            if (File.Exists(pathToFile))
            {
                pathToFile = Path.GetFullPath(pathToFile); //STANDARDIZE INPUT IF FILE EXISTS (it might be a memory file!)
            }

            IMEPackage package;

            if (forceLoadFromDisk || !GlobalSharedCacheEnabled || quickLoad) //Quick loaded packages cannot be cached
            {
                using (FileStream fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
                {
                    package = LoadPackage(fs, pathToFile, false, quickLoad);
                }
            }
            else
            {
                package = openPackages.GetOrAdd(pathToFile, fpath =>
                {
                    using (FileStream fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
                    {
                        Debug.WriteLine($"Adding package to package cache (File): {fpath}");
                        return(LoadPackage(fs, fpath, true));
                    }
                });
            }



            if (user != null)
            {
                package.RegisterTool(user);
                addToPackagesInTools(package);
            }
            else
            {
                package.RegisterUse();
            }
            return(package);
        }
예제 #7
0
        /// <summary>
        /// Opens a package from a stream. Ensure the position is correctly set to the start of the package.
        /// </summary>
        /// <param name="inStream"></param>
        /// <param name="associatedFilePath"></param>
        /// <param name="useSharedPackageCache"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static IMEPackage OpenMEPackageFromStream(Stream inStream, string associatedFilePath = null, bool useSharedPackageCache = false, IPackageUser user = null, bool quickLoad = false)
        {
            IMEPackage package;

            if (associatedFilePath == null || !useSharedPackageCache || !GlobalSharedCacheEnabled || quickLoad)
            {
                package = LoadPackage(inStream, associatedFilePath, false, quickLoad);
            }
            else
            {
                package = openPackages.GetOrAdd(associatedFilePath, fpath =>
                {
                    Debug.WriteLine($"Adding package to package cache (Stream): {associatedFilePath}");
                    return(LoadPackage(inStream, associatedFilePath, true));
                });
            }

            if (user != null)
            {
                package.RegisterTool(user);
                addToPackagesInTools(package);
            }
            else
            {
                package.RegisterUse();
            }
            return(package);
        }