示例#1
0
 private void ChangeModButton_Click(object sender, EventArgs e)
 {
     using (SelectModForm f = new SelectModForm())
     {
         f.ShowDialog(this);
         BF2Mod mod = f.GetSelectedMod();
         if (mod != null)
         {
             SelectedMod                      = mod;
             SelectedModLabel.Text            = $"{SelectedMod.Title} ({SelectedMod.Name})";
             Settings.Default.LastSelectedMod = SelectedMod.Name;
             Settings.Default.Save();
         }
     }
 }
示例#2
0
        /// <summary>
        /// Starts the Battlefield 2 Server application
        /// </summary>
        /// <param name="Mod">The battlefield 2 mod that the server is to use</param>
        /// <param name="ExtraArgs">Any arguments to be past to the application on startup</param>
        public static void Start(BF2Mod Mod, string ExtraArgs)
        {
            // Make sure the server isnt running already
            if (IsRunning)
            {
                throw new Exception("Battlefield 2 is already running!");
            }

            // Make sure the mod is supported!
            if (!Mods.Contains(Mod))
            {
                throw new Exception("The battlefield 2 mod cannot be located in the mods folder");
            }

            // Start new BF2 proccess
            ProcessStartInfo Info = new ProcessStartInfo();

            Info.Arguments = String.Format(" +modPath mods/{0}", Mod.Name.ToLower());
            if (!String.IsNullOrEmpty(ExtraArgs))
            {
                Info.Arguments += " " + ExtraArgs;
            }

            // Start process. Set working directory so we dont get errors!
            Info.FileName         = "bf2.exe";
            Info.WorkingDirectory = RootPath;
            ClientProcess         = Process.Start(Info);

            // Hook into the proccess so we know when its running, and register a closing event
            ClientProcess.EnableRaisingEvents = true;
            ClientProcess.Exited += ServerProcess_Exited;

            // Call event
            if (Started != null)
            {
                Started();
            }

            while (!ClientProcess.WaitForInputIdle(50))
            {
                Application.DoEvents();
            }
        }
示例#3
0
        /// <summary>
        /// Loads a battlefield 2 server into this object for use.
        /// </summary>
        /// <param name="Bf2Path">The full root path to the server's executable file</param>
        public static void SetInstallPath(string Bf2Path)
        {
            // Make sure we have a valid server path
            if (!File.Exists(Path.Combine(Bf2Path, "bf2.exe")) && !File.Exists(Path.Combine(Bf2Path, "bf2_w32ded.exe")))
            {
                throw new ArgumentException("Invalid BF2 installation path");
            }

            // Make sure we actually changed server paths before processing
            if (!String.IsNullOrEmpty(RootPath) && (new Uri(Bf2Path)) == (new Uri(RootPath)))
            {
                // Same path is selected, just return
                return;
            }

            // Temporary variables
            string        Modpath  = Path.Combine(Bf2Path, "mods");
            List <BF2Mod> TempMods = new List <BF2Mod>();

            // Make sure the server has the required folders
            if (!Directory.Exists(Modpath))
            {
                // Write trace
                throw new Exception("Unable to locate the 'mods' folder. Please make sure you have selected a valid "
                                    + "battlefield 2 installation path before proceeding.");
            }

            // Load all found mods, discarding invalid mods
            ModLoadErrors = new List <string>();
            IEnumerable <string> ModList = from dir in Directory.GetDirectories(Modpath) select dir.Substring(Modpath.Length + 1);

            foreach (string Name in ModList)
            {
                try
                {
                    // Create a new instance of the mod, and store it for later
                    BF2Mod Mod = new BF2Mod(Modpath, Name);
                    TempMods.Add(Mod);
                }
                catch (InvalidModException E)
                {
                    ModLoadErrors.Add(E.Message);
                    continue;
                }
                catch (Exception E)
                {
                    ModLoadErrors.Add(E.Message);
                }
            }

            // We need mods bro...
            if (TempMods.Count == 0)
            {
                throw new Exception("No valid battlefield 2 mods could be found in the Bf2 Server mods folder!");
            }

            // Define var values after we now know this server apears valid
            RootPath = Bf2Path;
            Mods     = TempMods;

            // Fire change event
            if (PathChanged != null)
            {
                PathChanged();
            }

            // Recheck server process
            CheckServerProcess();
        }
示例#4
0
        /// <summary>
        /// Loads a battlefield 2 server into this object for use.
        /// </summary>
        /// <param name="Bf2Path">The full root path to the server's executable file</param>
        public static void SetInstallPath(string Bf2Path)
        {
            // Make sure we have a valid server path
            if (!File.Exists(Path.Combine(Bf2Path, "bf2.exe")) && !File.Exists(Path.Combine(Bf2Path, "bf2_w32ded.exe")))
            {
                throw new ArgumentException("Invalid BF2 installation path");
            }

            // Make sure we actually changed server paths before processing
            if (!String.IsNullOrEmpty(RootPath) && (new Uri(Bf2Path)) == (new Uri(RootPath)))
            {
                // Same path is selected, just return
                return;
            }

            // Temporary variables
            string Modpath = Path.Combine(Bf2Path, "mods");
            List<BF2Mod> TempMods = new List<BF2Mod>();

            // Make sure the server has the required folders
            if (!Directory.Exists(Modpath))
            {
                // Write trace
                throw new Exception("Unable to locate the 'mods' folder. Please make sure you have selected a valid "
                    + "battlefield 2 installation path before proceeding.");

            }

            // Load all found mods, discarding invalid mods
            ModLoadErrors = new List<string>();
            IEnumerable<string> ModList = from dir in Directory.GetDirectories(Modpath) select dir.Substring(Modpath.Length + 1);
            foreach (string Name in ModList)
            {
                try
                {
                    // Create a new instance of the mod, and store it for later
                    BF2Mod Mod = new BF2Mod(Modpath, Name);
                    TempMods.Add(Mod);
                }
                catch (InvalidModException E)
                {
                    ModLoadErrors.Add(E.Message);
                    continue;
                }
                catch (Exception E)
                {
                    ModLoadErrors.Add(E.Message);
                }
            }

            // We need mods bro...
            if (TempMods.Count == 0)
            {
                throw new Exception("No valid battlefield 2 mods could be found in the Bf2 Server mods folder!");
            }

            // Define var values after we now know this server apears valid
            RootPath = Bf2Path;
            Mods = TempMods;

            // Fire change event
            if (PathChanged != null)
                PathChanged();
            
            // Recheck server process
            CheckServerProcess();
        }
示例#5
0
        /// <summary>
        /// Starts the Battlefield 2 Server application
        /// </summary>
        /// <param name="Mod">The battlefield 2 mod that the server is to use</param>
        /// <param name="ExtraArgs">Any arguments to be past to the application on startup</param>
        public static void Start(BF2Mod Mod, string ExtraArgs)
        {
            // Make sure the server isnt running already
            if (IsRunning)
                throw new Exception("Battlefield 2 is already running!");

            // Make sure the mod is supported!
            if (!Mods.Contains(Mod))
                throw new Exception("The battlefield 2 mod cannot be located in the mods folder");

            // Start new BF2 proccess
            ProcessStartInfo Info = new ProcessStartInfo();
            Info.Arguments = String.Format(" +modPath mods/{0}", Mod.Name.ToLower());
            if (!String.IsNullOrEmpty(ExtraArgs))
                Info.Arguments += " " + ExtraArgs;

            // Start process. Set working directory so we dont get errors!
            Info.FileName = "bf2.exe";
            Info.WorkingDirectory = RootPath;
            ClientProcess = Process.Start(Info);

            // Hook into the proccess so we know when its running, and register a closing event
            ClientProcess.EnableRaisingEvents = true;
            ClientProcess.Exited += ServerProcess_Exited;

            // Call event
            if (Started != null)
                Started();

            while (!ClientProcess.WaitForInputIdle(50)) Application.DoEvents();
        }
示例#6
0
        /// <summary>
        /// Sets the working for Battlefield 2
        /// </summary>
        /// <param name="folderPath"></param>
        private void LoadBf2Directory(string folderPath)
        {
            // Try and load battlefield 2 mods
            BF2Client.SetInstallPath(folderPath);

            // check for ESAI
            bool esai = Directory.Exists(Path.Combine(folderPath, "mods", "bf2", "ESAI"));

            // Enable buttons on the form
            ChangeModButton.Enabled = true;
            LoadObjectsButton.Enabled = true;

            // Set texts
            DirectoryLabel.Text = folderPath;
            EsaiLabel.Text = (esai) ? "Yes" : "No";

            // Selected Mod
            if (!String.IsNullOrWhiteSpace(Settings.Default.LastSelectedMod))
            {
                SelectedMod = BF2Client.Mods
                    .Where(x => x.Name == Settings.Default.LastSelectedMod)
                    .FirstOrDefault();

                // If mod is null, we changed paths maybe?
                if (SelectedMod != null)
                {
                    SelectedModLabel.Text = $"{SelectedMod.Title} ({SelectedMod.Name})";
                }
            }
        }
示例#7
0
 private void ChangeModButton_Click(object sender, EventArgs e)
 {
     using (SelectModForm f = new SelectModForm())
     {
         f.ShowDialog(this);
         BF2Mod mod = f.GetSelectedMod();
         if (mod != null)
         {
             SelectedMod = mod;
             SelectedModLabel.Text = $"{SelectedMod.Title} ({SelectedMod.Name})";
             Settings.Default.LastSelectedMod = SelectedMod.Name;
             Settings.Default.Save();
         }
     }
 }