using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
namespace SL_Switcher
{
public class BadMetadataException : Exception
{
private string m_path;
private string m_field;
public BadMetadataException(string path, string field, string message) : base(message)
{
m_field = field;
m_path = path;
}
public string Path
{
get { return m_path; }
}
public string Field
{
get { return m_field; }
}
}
///
/// Data about a SL version
///
public class Program
{
public enum VersionState
{
Experimental,
Beta,
Stable,
Official
}
private string m_name;
private string m_provider;
private VersionState m_versionstate;
private string m_cachedpath;
private string m_executable;
private string m_arguments;
private string m_version;
public Program()
{
}
public Program(string name, string provider, string version, string sl_version, VersionState vs) : this()
{
Name = name;
Provider = provider;
AppVersion = version;
State = vs;
}
public Program(RegistryKey key, string vendor, string product) : this()
{
Load(key, vendor, product);
}
///
/// Loads the information from a registry key
///
/// Key to load from
public virtual void Load(RegistryKey key, string vendor, string name)
{
Provider = vendor;
Name = name;
CachedPath = GetStr(key, "Path");
Executable = GetStr(key, "Executable");
Arguments = GetStr(key, "Arguments");
AppVersion = GetStr(key, "Version");
}
internal string GetStr(RegistryKey k, string value)
{
string ret = null;
ret = (string)k.GetValue(value);
if (ret == null)
{
throw new BadMetadataException(k.Name, value, "Missing registry key: " + value);
}
return ret;
}
internal int GetInt(RegistryKey k, string value)
{
if (k.GetValue(value,null) == null)
{
throw new BadMetadataException(k.Name, value, "Missing registry key: " + value );
}
return (int)k.GetValue(value);
}
#region Properties
///
/// Application name
///
public string Name
{
get { return m_name; }
set { m_name = value;}
}
///
/// Who provides the application
///
public string Provider
{
get { return m_provider; }
set { m_provider = value; }
}
///
/// Application version
///
public string AppVersion
{
get { return m_version; }
set { m_version = value;}
}
///
/// Stability state
///
public VersionState State
{
get { return m_versionstate; }
set { m_versionstate = value; }
}
///
/// Cached path (copy)
///
public string CachedPath
{
get { return m_cachedpath; }
set { m_cachedpath = value; }
}
///
/// Executable path (relative to directory)
///
public string Executable
{
get { return m_executable; }
set { m_executable = value; }
}
///
/// Arguments to run the executable with
///
public string Arguments
{
get { return m_arguments; }
set { m_arguments = value; }
}
#endregion
}
}