/// <summary>
        /// Attempts to locate the command line client executable.
        /// </summary>
        /// <param name="type">
        /// Which client type to attempt to locate; or <c>null</c> to locate any.
        /// </param>
        /// <returns>
        /// A <see cref="KeyValuePair{TKey,TValue}"/> containing the type of client
        /// located and the full path to the client executable, or an empty value if no client could be located.
        /// </returns>
        private static KeyValuePair<GuiClientType, string> LocateClient(GuiClientType? type)
        {
            IEnumerable<string> paths =
                from path in Environment.GetEnvironmentVariable("PATH").Split(';')
                where !StringEx.IsNullOrWhiteSpace(path)
                select path.Trim();

            if (type == null || type == GuiClientType.PyQT)
            {
                string client =
                    (from path in paths
                     let executablePath = Path.Combine(path, "thg.exe")
                     where File.Exists(executablePath)
                     select executablePath).FirstOrDefault();
                if (client != null)
                    return new KeyValuePair<GuiClientType, string>(GuiClientType.PyQT, client);
            }

            if (type == null || type == GuiClientType.PyGTK)
            {
                string client =
                    (from path in paths
                     let executablePath = Path.Combine(path, "hgtk.exe")
                     where File.Exists(executablePath)
                     select executablePath).FirstOrDefault();
                if (client != null)
                    return new KeyValuePair<GuiClientType, string>(GuiClientType.PyGTK, client);
            }

            return new KeyValuePair<GuiClientType, string>(GuiClientType.None, string.Empty);
        }
Esempio n. 2
0
 /// <summary>
 /// This method will throw a <see cref="InvalidOperationException"/> if the "wrong" client type is installed, to
 /// signal that a given property on a command object can only be used from a specific client type.
 /// </summary>
 /// <param name="propertyName">
 /// The name of the property.
 /// </param>
 /// <param name="requiredClientType">
 /// The required client type.
 /// </param>
 /// <exception cref="InvalidOperationException">
 /// The property is not available in the installed client.
 /// </exception>
 protected static void EnsurePropertyAvailability(string propertyName, GuiClientType requiredClientType)
 {
     if (GuiClient.ClientType != requiredClientType)
     {
         throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} is not available in the installed client", propertyName));
     }
 }
        static GuiClient()
        {
            KeyValuePair<GuiClientType, string> result = LocateClient(null);
            ClientPath = result.Value;
            _ClientType = result.Key;

            Initialize();
        }
        /// <summary>
        /// Assigns the <see cref="Current"/> <see cref="TortoiseHgClient"/> implementation based on the
        /// <see cref="GuiClientType"/> specified.
        /// </summary>
        /// <param name="clientType">
        /// The <see cref="GuiClientType"/> to assign the client for.
        /// </param>
        /// <exception cref="InvalidOperationException">Internal error, unknown client type passed to TortoiseHgClient.AssignCurrent</exception>
        internal static void AssignCurrent(GuiClientType clientType)
        {
            switch (clientType)
            {
                case GuiClientType.PyGTK:
                    Current = new TortoiseHgPyGTKClient();
                    break;

                case GuiClientType.PyQT:
                    Current = new TortoiseHgPyQTClient();
                    break;

                default:
                    throw new InvalidOperationException("Internal error, unknown client type passed to TortoiseHgClient.AssignCurrent");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Assigns the <see cref="Current"/> <see cref="TortoiseHgClient"/> implementation based on the
        /// <see cref="GuiClientType"/> specified.
        /// </summary>
        /// <param name="clientType">
        /// The <see cref="GuiClientType"/> to assign the client for.
        /// </param>
        /// <exception cref="System.InvalidOperationException">Internal error, unknown client type passed to TortoiseHgClient.AssignCurrent</exception>
        internal static void AssignCurrent(GuiClientType clientType)
        {
            switch (clientType)
            {
            case GuiClientType.PyGTK:
                Current = new TortoiseHgPyGTKClient();
                break;

            case GuiClientType.PyQT:
                Current = new TortoiseHgPyQTClient();
                break;

            default:
                throw new InvalidOperationException("Internal error, unknown client type passed to TortoiseHgClient.AssignCurrent");
            }
        }
        /// <summary>
        /// Determines if the specified client type is available on this system.
        /// </summary>
        /// <param name="clientType">
        /// The type of client to look for.
        /// </param>
        /// <returns>
        /// <c>true</c> if the client executable was located; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <para><paramref name="clientType"/> can not be <see cref="GuiClientType.None"/> or an undefined value.</para>
        /// </exception>
        public static bool GetClientAvailability(GuiClientType clientType)
        {
            if (clientType == GuiClientType.None)
                throw new ArgumentException("clientType cannot be GuiClientType.None");
            if (!Enum.IsDefined(typeof(GuiClientType), clientType))
                throw new ArgumentException("clientType must be a predefined value");

            return LocateClient(clientType).Key == clientType;
        }