示例#1
0
        public static IMEPackage OpenMEPackage(string pathToFile, WPFBase wpfWindow = null, WinFormsBase winForm = null)
        {
            IMEPackage package = null;

            if (!openPackages.ContainsKey(pathToFile))
            {
                ushort version;
                ushort licenseVersion;
                using (FileStream fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
                {
                    fs.Seek(4, SeekOrigin.Begin);
                    version        = fs.ReadValueU16();
                    licenseVersion = fs.ReadValueU16();
                }

                if (version == ME3Package.VERSION && licenseVersion == ME3Package.LICENSE)
                {
                    package = ME3ConstructorDelegate(pathToFile);
                }
                else if (version == 512 && licenseVersion == 130)
                {
                    package = ME2ConstructorDelegate(pathToFile);
                }
                else if (version == 491 && licenseVersion == 1008)
                {
                    package = ME1ConstructorDelegate(pathToFile);
                }
                else
                {
                    throw new FormatException("Not an ME1, ME2, or ME3 package file.");
                }
                package.noLongerUsed += Package_noLongerUsed;
                openPackages.Add(pathToFile, package);
            }
            else
            {
                package = openPackages[pathToFile];
            }

            if (wpfWindow != null)
            {
                package.RegisterTool(new GenericWindow(wpfWindow, Path.GetFileName(pathToFile)));
                addToPackagesInTools(package);
            }
            else if (winForm != null)
            {
                package.RegisterTool(new GenericWindow(winForm, Path.GetFileName(pathToFile)));
                addToPackagesInTools(package);
            }
            else
            {
                package.RegisterUse();
            }
            return(package);
        }
示例#2
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);
 }