RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

DataPath.cs : Ultima Online Classic registry keys

Scriptiz

Sorceror
It's been quite a long time that now when I'm launching RunUO, if I haven't specified a CustomPath in DataPath.cs, it will not find the newest installation directory.

Here is my fix to detect it automatically (no more needed to specify CustomPath if you have a full new UO Classic installation).

Rich (BB code):
public static void Configure()
{
    string pathUO = GetPath(@"Origin Worlds Online\Ultima Online\1.0", "ExePath");
    string pathTD = GetPath(@"Origin Worlds Online\Ultima Online Third Dawn\1.0", "ExePath"); //These refer to 2D & 3D, not the Third Dawn expansion
    string pathKR = GetPath(@"Origin Worlds Online\Ultima Online\KR Legacy Beta", "ExePath"); //After KR, This is the new registry key for the 2D client
    string pathSA = GetPath(@"Electronic Arts\EA Games\Ultima Online Stygian Abyss Classic", "InstallDir");
    string pathClassic = GetPath(@"Electronic Arts\EA Games\Ultima Online Classic", "InstallDir"); // Scriptiz : Classic client registry key (7.0.1x.x)
 
    if (CustomPath != null)
        Core.DataDirectories.Add(CustomPath);
 
    if (pathUO != null)
        Core.DataDirectories.Add(pathUO);
 
    if (pathTD != null)
        Core.DataDirectories.Add(pathTD);
 
    if (pathKR != null)
        Core.DataDirectories.Add(pathKR);
 
    if (pathSA != null)
        Core.DataDirectories.Add(pathSA);
 
    if (pathClassic != null)
        Core.DataDirectories.Add(pathClassic);
 
    if (Core.DataDirectories.Count == 0 && !Core.Service)
    {
        Console.WriteLine("Enter the Ultima Online directory:");
        Console.Write("> ");
 
        Core.DataDirectories.Add(Console.ReadLine());
    }
}

This is just three lines to add (with pathClassic)
 

Vorspire

Knight
The registry entries for UO are a little more complex than DataPath can handle, some installations have two keys that, when combined, form the full path - while other registry entries are under different paths for the same versions of UO - I addressed this issue with OpenUO's InstallationLocator and re-wrote the entire thing, it can now detect every possible combination of installations and may prove to be useful if implemented into the RunUO SVN :)

I offer the original source to the RunUO Team for reference or usage in the SVN - Every little helps :)
Code:
#region License Header
/***************************************************************************
 *   Copyright (c) 2011 OpenUO Software Team.
 *   All Right Reserved.
 *
 *   $Id: $:
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 ***************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Win32;
using OpenUO.Core.Diagnostics;

namespace OpenUO.Ultima
{
	public static class InstallationLocator
	{
		public static bool Is64Bit { get; private set; }
		public static List<string> KnownRegistryKeyValueNames { get; private set; }
		public static List<string> KnownInstallationRegistryKeys { get; private set; }

		static InstallationLocator()
		{
			Is64Bit = (IntPtr.Size == 8);

			KnownInstallationRegistryKeys = new List<string> {
                @"Electronic Arts\EA Games\Ultima Online Stygian Abyss Classic",     
                @"Origin Worlds Online\Ultima Online\KR Legacy Beta", 
                @"EA Games\Ultima Online: Mondain's Legacy\1.00.0000", 
                @"Origin Worlds Online\Ultima Online\1.0", 
                @"Origin Worlds Online\Ultima Online Third Dawn\1.0",
                @"EA GAMES\Ultima Online Samurai Empire", 
                @"EA Games\Ultima Online: Mondain's Legacy", 
                @"EA GAMES\Ultima Online Samurai Empire\1.0", 
                @"EA GAMES\Ultima Online Samurai Empire\1.00.0000", 
                @"EA GAMES\Ultima Online: Samurai Empire\1.0", 
                @"EA GAMES\Ultima Online: Samurai Empire\1.00.0000", 
                @"EA Games\Ultima Online: Mondain's Legacy\1.0", 
                @"EA Games\Ultima Online: Mondain's Legacy\1.00.0000", 
                @"Origin Worlds Online\Ultima Online Samurai Empire BETA\2d\1.0", 
                @"Origin Worlds Online\Ultima Online Samurai Empire BETA\3d\1.0", 
                @"Origin Worlds Online\Ultima Online Samurai Empire\2d\1.0", 
                @"Origin Worlds Online\Ultima Online Samurai Empire\3d\1.0",
                @"Electronic Arts\EA Games\Ultima Online Classic"
            };

			KnownRegistryKeyValueNames = new List<string> {
                @"ExePath",
                @"InstallDir",
                @"Install Dir",
                @"GameExecutionPath"
            };
		}

		public static IEnumerable<InstallLocation> Locate()
		{
			string prefix = Is64Bit ? @"SOFTWARE\Wow6432Node\" : @"SOFTWARE\";

			foreach (string knownKeyName in KnownInstallationRegistryKeys)
			{
				if (!String.IsNullOrWhiteSpace(knownKeyName))
				{
					string exePath;
					TryGetExePath(prefix + knownKeyName, out exePath);

					if (!String.IsNullOrWhiteSpace(exePath))
						yield return exePath;
				}
			}
		}

		private static bool TryGetExePath(string regPath, out string exePath)
		{
			try
			{
				using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regPath) ?? Registry.CurrentUser.OpenSubKey(regPath))
				{
					if (key == null)
					{
						exePath = null;
						return false;
					}

					string dir = null, file = null;

					foreach (string knownKeyValueName in KnownRegistryKeyValueNames)
					{
						string pathStub = key.GetValue(knownKeyValueName) as string;

						if (String.IsNullOrWhiteSpace(pathStub))
							continue;

						if (String.IsNullOrWhiteSpace(file) && Path.HasExtension(pathStub))
						{
							file = Path.GetFileName(pathStub);

							if (String.IsNullOrWhiteSpace(dir) && Path.IsPathRooted(pathStub))
								dir = Path.GetDirectoryName(pathStub);
						}

						if (String.IsNullOrWhiteSpace(dir) && Path.IsPathRooted(pathStub))
							dir = pathStub;

						if (!String.IsNullOrWhiteSpace(dir) && !String.IsNullOrWhiteSpace(file))
						{
							string fullPath = dir.Replace('/', '\\');

							if (fullPath[fullPath.Length - 1] != '\\')
								fullPath += '\\';

							fullPath += file;

							Tracer.Info(
								"Installation Detected -> {0}",
								fullPath);

							if (File.Exists(fullPath))
							{
								exePath = dir;
								return true;
							}
						}
					}
				}
			}
			catch (Exception e)
			{
				Tracer.Error(e);
			}

			exePath = null;
			return false;
		}
	}
}
 

Scriptiz

Sorceror
Thanks Vorspire, I was just hoping support to the newest client but your solution is more complete :)

I hope one of them will be included in the SVN.
 
Top