/// <summary>
        /// Sets pathes to required resources.
        /// Will also remove any existing resources from the current lists.
        /// </summary>
        /// <param name="PathStrings"></param>
        /// <param name="PathRooms"></param>
        /// <param name="PathObjects"></param>
        /// <param name="PathRoomTextures"></param>
        /// <param name="PathSounds"></param>
        /// <param name="PathMusic"></param>
        /// <param name="PathMails"></param>
        public void Init(
            string PathStrings,
            string PathRooms,
            string PathObjects,
            string PathRoomTextures,
            string PathSounds,
            string PathMusic,
            string PathMails)
        {
            this.StringsFolder      = PathStrings;
            this.RoomsFolder        = PathRooms;
            this.ObjectsFolder      = PathObjects;
            this.RoomTexturesFolder = PathRoomTextures;
            this.WavFolder          = PathSounds;
            this.MusicFolder        = PathMusic;
            this.MailFolder         = PathMails;

            string[] files;

            // already executed once?
            if (Initialized)
            {
                StringResources.Clear();
                StringDictionaries.Clear();
                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 string dictionaries for different servers
            if (Directory.Exists(StringsFolder))
            {
                // get available files
                files = Directory.GetFiles(StringsFolder, '*' + FileExtensions.RSB);

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

            // register objects
            if (Directory.Exists(ObjectsFolder))
            {
                // get available files
                files = Directory.GetFiles(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(RoomTexturesFolder))
            {
                // get available files
                files = Directory.GetFiles(RoomTexturesFolder, "grd*" + FileExtensions.BGF);

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

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

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

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

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

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

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

            // load mails
            if (Directory.Exists(MailFolder))
            {
                // read available mail files
                files = Directory.GetFiles(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;
        }
示例#2
0
        /// <summary>
        /// Sets pathes to required resources.
        /// Will also remove any existing resources from the current lists.
        /// </summary>
        /// <param name="PathStrings"></param>
        /// <param name="PathRooms"></param>
        /// <param name="PathObjects"></param>
        /// <param name="PathRoomTextures"></param>
        /// <param name="PathSounds"></param>
        /// <param name="PathMusic"></param>
        /// <param name="PathMails"></param>
        public void Init(
            string PathStrings,
            string PathRooms,
            string PathObjects,
            string PathRoomTextures,
            string PathSounds,
            string PathMusic,
            string PathMails)
        {
            this.StringsFolder      = PathStrings;
            this.RoomsFolder        = PathRooms;
            this.ObjectsFolder      = PathObjects;
            this.RoomTexturesFolder = PathRoomTextures;
            this.WavFolder          = PathSounds;
            this.MusicFolder        = PathMusic;
            this.MailFolder         = PathMails;

            string[] files;

            // already executed once?
            if (Initialized)
            {
                StringResources.Clear();
                StringDictionaries.Clear();
                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 string dictionaries for different servers
            if (Directory.Exists(StringsFolder))
            {
                // get available files
                files = Directory.GetFiles(StringsFolder, '*' + FileExtensions.RSB);

                foreach (string s in files)
                {
                    StringDictionaries.TryAdd(Path.GetFileName(s), null);
                }
            }
            else
            {
                Directory.CreateDirectory(StringsFolder);
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

#if !VANILLA && !OPENMERIDIAN
                    // Fix timestamp if necessary and write out mail.
                    if (!mail.IsTimestampUpdated)
                    {
                        mail.Timestamp         += MeridianDate.CONVERTOFFSET;
                        mail.IsTimestampUpdated = true;
                        mail.Save(s);
                    }
#endif
                    // add to list
                    Mails.Add(mail);
                }
            }
            else
            {
                Directory.CreateDirectory(MailFolder);
            }

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

            // forced GC collection
            Util.ForceMaximumGC();

            // mark initialized
            Initialized = true;
        }
示例#3
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;
        }