コード例 #1
0
        /// <summary>
        /// Clears and reloads the strings from another dictionary file within the strings folder,
        /// which was previously initialized during Init()
        /// </summary>
        /// <param name="RsbFile">Plain filename, like rsc0000.rsb</param>
        /// <param name="Language"></param>
        public void SelectStringDictionary(string RsbFile, LanguageCode Language)
        {
            // clear old entries
            StringResources.Clear();

            // set preferred language
            StringResources.Language = Language;

            // try get the dictionary for argument
            RsbFile file = GetStringDictionary(RsbFile);

            // load strings of the rsbfile to use
            // into the multithreaded dictionary
            if (file != null)
            {
                foreach (RsbResourceID res in file.StringResources)
                {
                    StringResources.TryAdd(res.ID, res.Text, res.Language);
                }
            }

            // raise event
            if (StringDictionarySelected != null)
            {
                StringDictionarySelected(this, new EventArgs());
            }
        }
コード例 #2
0
        /// <summary>
        /// Tries to retrieve a RSB file from the Strings dictionary.
        /// Will load the file from disk, if not yet loaded.
        /// </summary>
        /// <param name="File">Plain filename with extension (e.g. rsc0000.rsb)</param>
        /// <returns></returns>
        public RsbFile GetStringDictionary(string File)
        {
            RsbFile rsbFile = null;

            // if the file is known
            if (StringDictionaries.TryGetValue(File, out rsbFile))
            {
                // haven't loaded it yet?
                if (rsbFile == null)
                {
                    // load it
                    rsbFile = new RsbFile(StringsFolder + "/" + File);

                    // update the registry
                    StringDictionaries.TryUpdate(File, rsbFile, null);
                }
            }

            return(rsbFile);
        }
コード例 #3
0
        /// <summary>
        /// Clears and reloads the strings from another dictionary file.
        /// </summary>
        /// <param name="RsbFile"></param>
        public void ReloadStrings(string RsbFile)
        {
            // update stringfile
            Config.StringResourcesFile = RsbFile;

            // clear old entries
            StringResources.Clear();

            // check if new string dictionary exists
            if (File.Exists(Config.StringResourcesFile))
            {
                // load string resources
                RsbFile rsbFile = new RsbFile(Config.StringResourcesFile);

                // add to dictionary
                foreach (KeyValuePair <uint, string> pair in rsbFile.StringResources)
                {
                    StringResources.TryAdd(pair.Key, pair.Value);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Clears and reloads the strings from another dictionary file within the strings folder,
        /// which was previously initialized during Init()
        /// </summary>
        /// <param name="RsbFile">Plain filename, like rsc0000.rsb</param>
        /// <param name="Language"></param>
        public void SelectStringDictionary(string RsbFile, LanguageCode Language)
        {
            // clear old entries
            StringResources.Clear();

            // set preferred language
            StringResources.Language = Language;

            // Save the MD5 hash of this rsb file as our RsbHash.
            byte[]     rsbMD5Hash = MeridianMD5.ComputeGenericFileMD5(StringsFolder + "/" + RsbFile);
            Hash128Bit rsbHash    = new Hash128Bit();

            rsbHash.HASH1 = BitConverter.ToUInt32(rsbMD5Hash, 0);
            rsbHash.HASH2 = BitConverter.ToUInt32(rsbMD5Hash, 4);
            rsbHash.HASH3 = BitConverter.ToUInt32(rsbMD5Hash, 8);
            rsbHash.HASH4 = BitConverter.ToUInt32(rsbMD5Hash, 12);
            RsbHash       = rsbHash;

            // try get the dictionary for argument
            RsbFile file = GetStringDictionary(RsbFile);

            // load strings of the rsbfile to use
            // into the multithreaded dictionary
            if (file != null)
            {
                foreach (RsbResourceID res in file.StringResources)
                {
                    StringResources.TryAdd(res.ID, res.Text, res.Language);
                }
            }

            // raise event
            if (StringDictionarySelected != null)
            {
                StringDictionarySelected(this, new EventArgs());
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes the ResourceManager from given config.
        /// </summary>
        /// <param name="Config"></param>
        public void InitConfig(ResourceManagerConfig Config)
        {
            string[] files;

            // save new config
            this.Config = Config;

            // already executed once?
            if (Initialized)
            {
                // clear current string dictionary
                StringResources.Clear();

                // clear current lookup dictionaries
                Objects.Clear();
                RoomTextures.Clear();
                Rooms.Clear();
                Wavs.Clear();
                Music.Clear();

                // detach mail listener so we don't delete them
                Mails.ListChanged -= OnMailsListChanged;

                // clear our objects
                Mails.Clear();
            }

            // register strings
            if (File.Exists(Config.StringResourcesFile))
            {
                // load string resources
                RsbFile rsbFile = new RsbFile(Config.StringResourcesFile);

                // add to dictionary
                foreach (KeyValuePair <uint, string> pair in rsbFile.StringResources)
                {
                    StringResources.TryAdd(pair.Key, pair.Value);
                }
            }

            // register objects
            if (Directory.Exists(Config.ObjectsFolder))
            {
                // get available files
                files = Directory.GetFiles(Config.ObjectsFolder, '*' + FileExtensions.BGF);

                foreach (string s in files)
                {
                    string filename = Path.GetFileName(s);

                    if (!filename.StartsWith("grd"))
                    {
                        Objects.TryAdd(filename, null);
                    }
                }
            }

            // register roomtextures
            if (Directory.Exists(Config.RoomTexturesFolder))
            {
                // get available files
                files = Directory.GetFiles(Config.RoomTexturesFolder, "grd*" + FileExtensions.BGF);

                foreach (string s in files)
                {
                    RoomTextures.TryAdd(Path.GetFileName(s), null);
                }
            }

            // register rooms
            if (Directory.Exists(Config.RoomsFolder))
            {
                // get available files
                files = Directory.GetFiles(Config.RoomsFolder, '*' + FileExtensions.ROO);

                foreach (string s in files)
                {
                    Rooms.TryAdd(Path.GetFileName(s), null);
                }
            }

            // register wav sounds
            if (Directory.Exists(Config.WavFolder))
            {
                // get available files
                files = Directory.GetFiles(Config.WavFolder, '*' + FileExtensions.WAV);

                foreach (string s in files)
                {
                    Wavs.TryAdd(Path.GetFileName(s), null);
                }
            }

            // register music
            if (Directory.Exists(Config.MusicFolder))
            {
                // get available files
                files = Directory.GetFiles(Config.MusicFolder, '*' + FileExtensions.MP3);

                foreach (string s in files)
                {
                    Music.TryAdd(Path.GetFileName(s), null);
                }
            }

            // load mails
            if (Directory.Exists(Config.MailFolder))
            {
                // read available mail files
                files = Directory.GetFiles(Config.MailFolder, '*' + FileExtensions.XML);
                foreach (string s in files)
                {
                    // create mail object
                    Mail mail = new Mail();

                    // load values from xml
                    mail.Load(s);

                    // add to list
                    Mails.Add(mail);
                }
            }

            // hookup mails listener to write/delete the files
            Mails.ListChanged += OnMailsListChanged;

            // forced GC collection
            GC.Collect(2);

            // mark initialized
            Initialized = true;
        }