コード例 #1
0
        private void uiAddButton_Click(object sender, RoutedEventArgs e)
        {
            // get selected game
            GameListItem gameListItem = (GameListItem)uiGameComboBox.SelectedItem;

            if (gameListItem == null)
            {
                Common.Message(this, "Select a game first.");
                return;
            }

            // open file dialog
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

            dialog.Title            = "Add Map";
            dialog.Filter           = "BSP files (*.bsp)|*.bsp";
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            String mapFileName = System.IO.Path.GetFileName(dialog.FileName);

            // calculate checksum
            UInt32 checksum = 0;

            try
            {
                checksum = HalfLifeMapChecksum.Calculate(dialog.FileName);
            }
            catch (Exception ex)
            {
                Common.Message(this, String.Format("Error calculate map checksum for map \"{0}\"", mapFileName), ex, MessageWindow.Flags.Error);
                return;
            }

            // see if map is built-in
            if (gameListItem.Game.BuiltInMapExists(checksum, System.IO.Path.GetFileNameWithoutExtension(mapFileName)))
            {
                Common.Message(this, String.Format("The map \"{0}\" with the checksum \"{1}\" is a built-in map. It does not need to be added to the map pool.", mapFileName, checksum));
                return;
            }

            // see if the game map folder already exists
            //String engine = (game.Engine == Demo.EngineEnum.Source ? "source" : "goldsrc");
            String engine        = "goldsrc";
            String gameMapFolder = Config.ProgramDataPath + String.Format("\\maps\\{0}\\{1}", engine, gameListItem.Game.Folder);

            if (!Directory.Exists(gameMapFolder))
            {
                Directory.CreateDirectory(gameMapFolder);
            }

            // see if the checksum folder already exists
            String checksumFolder = gameMapFolder + "\\" + String.Format("{0}", checksum);

            if (!Directory.Exists(checksumFolder))
            {
                Directory.CreateDirectory(checksumFolder);
            }

            // see if the map already exists
            String mapFullPath = checksumFolder + "\\" + mapFileName;

            if (File.Exists(mapFullPath))
            {
                Common.Message(this, String.Format("The map \"{0}\" with the checksum \"{1}\" already exists.", mapFileName, checksum));
                return;
            }

            // copy the map over
            File.Copy(dialog.FileName, mapFullPath);

            // update UI and inform the user of success
            RefreshMapListView();
            Common.Message(this, String.Format("Successfully added the map \"{0}\" with the checksum \"{1}\" to the map pool.", mapFileName, checksum));
        }
コード例 #2
0
ファイル: Launcher.cs プロジェクト: Hengle/coldemoplayer
        protected void CheckMapVersion()
        {
            // FIXME:
            // not really needed, just don't call this
            // remove me when source map checksum stuff is figured out
            if (Demo.Engine == Demo.Engines.Source)
            {
                return;
            }

            // see if the game has a config file
            // FIXME: engine name - assuming goldsrc for now (see above)
            Game game = GameManager.Find(Demo);

            if (game == null || game.HasConfig == false)
            {
                // can't determine what maps are built-in for the game - can't handle map versions
                return;
            }

            // see if the map is built-in
            if (game.BuiltInMapExists(Demo.MapChecksum, Demo.MapName))
            {
                // ok, suitable map found
                return;
            }

            // see if the map already exists in the game's "maps" folder
            String mapDestinationPath     = gameFullPath + "\\maps";
            String mapDestinationFileName = mapDestinationPath + "\\" + Demo.MapName + ".bsp";

            if (File.Exists(mapDestinationFileName))
            {
                if (HalfLifeMapChecksum.Calculate(mapDestinationFileName) == Demo.MapChecksum)
                {
                    // ok, suitable map found
                    return;
                }
            }

            // see if we have a map in the map pool matching the checksum
            String mapSourcePath     = Config.ProgramDataPath + "\\maps\\goldsrc\\" + String.Format("{0}\\{1}", Demo.GameFolderName, Demo.MapChecksum);
            String mapSourceFileName = mapSourcePath + "\\" + Demo.MapName + ".bsp";

            if (!File.Exists(mapSourceFileName))
            {
                DownloadMapWindow downloadMapWindow = new DownloadMapWindow(Demo.MapName, Config.MapsUrl + "goldsrc/" + String.Format("{0}/{1}_{2}.zip", Demo.GameFolderName, Demo.MapChecksum, Demo.MapName), mapSourcePath + "\\" + Demo.MapName + ".zip");
                downloadMapWindow.Owner = Owner;

                if (downloadMapWindow.ShowDialog() == false)
                {
                    // can't find a suitable map
                    if (Common.Message(Owner, String.Format("Can't find a version of \"{0}\" with a matching checksum \"{1}\" for this demo. Continue with playback anyway?", Demo.MapName, Demo.MapChecksum), null, MessageWindow.Flags.ContinueAbort) != MessageWindow.Result.Continue)
                    {
                        throw new AbortLaunchException();
                    }

                    return;
                }
            }

            // first make sure the desination "maps" folder exists (create it if it doesn't)
            if (!Directory.Exists(mapDestinationPath))
            {
                Directory.CreateDirectory(mapDestinationPath);
            }

            // if original map exists, rename to *.bak (if that exists, just delete it)
            String backupDestinationFileName = Path.ChangeExtension(mapDestinationFileName, ".bak");

            if (File.Exists(mapDestinationFileName))
            {
                if (File.Exists(backupDestinationFileName))
                {
                    File.Delete(backupDestinationFileName);
                }

                File.Move(mapDestinationFileName, backupDestinationFileName);
                FileOperationList.Add(new FileMoveOperation(backupDestinationFileName, mapDestinationFileName));
            }

            // copy old version of map
            File.Copy(mapSourceFileName, mapDestinationFileName);
            FileOperationList.Add(new FileDeleteOperation(mapDestinationFileName));

            // copy any wad files (if they don't already exist)
            DirectoryInfo directoryInfo = new DirectoryInfo(mapSourcePath);

            foreach (FileInfo fi in directoryInfo.GetFiles("*.wad", SearchOption.TopDirectoryOnly))
            {
                // wad destination = demo destination
                String wadDestinationFileName = gameFullPath + "\\" + fi.Name;

                if (!File.Exists(wadDestinationFileName))
                {
                    File.Copy(fi.FullName, wadDestinationFileName);
                }
            }
        }