예제 #1
0
        /// <summary>Initialises a new system.</summary>
        /// <param name="commandLineArguments">The command line arguments.</param>
        /// <param name="resourceProvider">The resource provider.</param>
        protected Sys(string[] commandLineArguments, ResourceProvider resourceProvider)
        {
            _commandLineArguments = commandLineArguments;

            _sfxPlayer = new SfxPlayer();

            if(resourceProvider != null)
            {
                _resourceProvider = resourceProvider;
            }
            else
            {
                int rpkFileIndex = -1;
                rpkFileIndex = IndexOfCommandLineArgument("-rpk");
                if(rpkFileIndex != -1)
                {
                    rpkFileIndex++;

                    if(rpkFileIndex == _commandLineArguments.Length)
                        throw new Exception("The RPK file was not specified after the -rpk command!");

                    if(!File.Exists(_commandLineArguments[rpkFileIndex]))
                        throw new FileNotFoundException("The RPK file specified by -rpk does not exist!");
                }
                else
                {
                    for(int i = 0; i < _commandLineArguments.Length; i++)
                    {
                        if(string.Compare(Path.GetExtension(_commandLineArguments[i]), ".rpk", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            rpkFileIndex = i;
                            break;
                        }
                    }
                }

                if(rpkFileIndex != -1)
                {   // RPK file specified
                    _resourceProvider = new RPKResourceProvider(File.ReadAllBytes(_commandLineArguments[rpkFileIndex]));
                }
                else
                {   // Resources provided by the file system
                    _resourceProvider = new FileResourceProvider();

                    // Check for -gamedir
                    int index = IndexOfCommandLineArgument("-gamedir");
                    if(index != -1 && index + 1 < _commandLineArguments.Length)
                    {
                        string path = _commandLineArguments[index + 1];

                        if(!Directory.Exists(path))
                            throw new DirectoryNotFoundException("The path specified by -gamedir does not exist!");

                        _gameDirectory = path;
                    }
                }
            }

            _introLogo = (IndexOfCommandLineArgument("-intrologo") != -1);
            _introInfo = (IndexOfCommandLineArgument("-introinfo") != -1);

            _strings = new Strings();

            _gameConfig = new GameConfig();
            LoadConfig();
        }
예제 #2
0
 /// <summary>Disposes resources.</summary>
 public virtual void Dispose()
 {
     if(_sfxPlayer != null)
     {
         try { _sfxPlayer.Dispose(); }
         catch { }
         _sfxPlayer = null;
     }
 }