예제 #1
0
        /// <summary>
        /// Load a File from the Disc
        /// </summary>
        /// <param name="flname">The Filename</param>
        /// <param name="sync">
        /// Only needed if a PackageMaintainer is used. This will tell the Maintainer, that
        /// it should reload the Package from the Disk, and not only get the Package in Memory
        /// </param>
        /// <returns>true, if the file was loaded</returns>
        public bool LoadFromFile(string flname, bool sync)
        {
            bool res = false;

            try
            {
                FileNameEventArg e = new FileNameEventArg(flname);
                if (BeforeFileLoad != null)
                {
                    BeforeFileLoad(this, e);
                }
                if (e.Cancel)
                {
                    return(false);
                }

                Wait.SubStart();
                Wait.Message = "Loading File";

                if (pkg != null)
                {
                    this.SetupEvents(false);
                }

                pkg = SimPe.Packages.File.LoadFromFile(e.FileName, sync);
                if (pkg.Index.Length < Helper.WindowsRegistry.BigPackageResourceCount)
                {
                    pkg.LoadCompressedState();
                }

                this.SetupEvents(true);
                Helper.WindowsRegistry.AddRecentFile(flname);

                Wait.SubStop();

                if (AfterFileLoad != null)
                {
                    AfterFileLoad(this);
                }
                res = true;
            }
#if !DEBUG
            catch (Exception ex) { SimPe.Helper.ExceptionMessage(ex); }
#endif
            finally { }
            if (res != true)
            {
                pkg = null;
            }
            return(res);
        }
예제 #2
0
        /// <summary>
        /// Load another Package
        /// </summary>
        /// <param name="newpkg">the Package that should be the currently opened</param>
        /// <returns>true, if the file was loaded</returns>
        public bool LoadFromPackage(SimPe.Packages.GeneratableFile newpkg)
        {
            if (newpkg == null)
            {
                return(false);
            }
            string flname = newpkg.FileName;

            if (flname == null)
            {
                flname = "";
            }

            FileNameEventArg e = new FileNameEventArg(flname);

            if (BeforeFileLoad != null)
            {
                BeforeFileLoad(this, e);
            }
            if (e.Cancel)
            {
                return(false);
            }

            if (pkg != null)
            {
                this.SetupEvents(false);
            }

            pkg = newpkg;
            pkg.LoadCompressedState();

            if (pkg != null)
            {
                this.SetupEvents(true);
            }

            if (pkg.FileName != null)
            {
                Helper.WindowsRegistry.AddRecentFile(pkg.FileName);
            }
            if (AfterFileLoad != null)
            {
                AfterFileLoad(this);
            }

            return(true);
        }