using System.Xml.Serialization;
namespace NaGet.Packages
{
///
/// インストーラーの種類を表す。
///
public enum InstallerType
{
///
/// インストーラー
///
[XmlEnum(Name="installer")]
EXEC_INSTALLER,
///
/// Microsoft Software Installer
///
[XmlEnum(Name="msi")]
MSI_PACKAGE,
///
/// 自己解凍書庫を含む書庫一般
///
[XmlEnum(Name="archive")]
ARCHIVE,
///
/// それ自身がプログラムそのものである
///
[XmlEnum(Name="itself")]
ITSELF,
///
/// インストールできない単なるデータ(BIOSなど)
///
[XmlEnum(Name="cannotinstall")]
CANNOT_INSTALL,
}
///
/// パッケージ情報を格納するクラス
///
public class Package
{
///
/// パッケージ名
///
public string Name;
///
/// バージョン文字列
///
public string Version;
///
/// パッケージの概要
///
public string Summary;
///
/// パッケージの解説
///
public string Description;
///
/// 公式サイトのURL
///
public LocationEntry Url;
///
/// 製作者の名前
///
public string Author;
///
/// インストーラーのタイプ
///
public InstallerType Type;
///
/// インストーラーが書庫内に入っているかのフラグ
///
public bool ArchivedInstaller = false;
///
/// アンインストーラーのレジストリのキー
///
public string UninstallerKey;
///
/// サイレントインストールのための引数。
/// インストーラー形式のみ有効で、nullもしくは空文字列の場合は
/// サイレントインストールができないことをあらわす
///
public string SilentInstallArguments;
///
/// インストールスクリプト(MSBuildドキュメント)
///
public string InstallScript;
///
/// アーカイブインストーラーのときのSystem32のコピー
///
public string System32CopyFiles;
///
/// インストーラーのリソースの配列
///
[XmlElement]
public Installer[] Installer;
///
/// 必要とされるパッケージの配列
///
[XmlArray(IsNullable=true),XmlArrayItem("Entry")]
public Entry[] Requires;
///
/// 競合するパッケージの配列
///
[XmlArray(IsNullable=true),XmlArrayItem("Entry")]
public Entry[] Conflicts;
///
/// タグ
///
public string Tags;
///
/// ライセンス
///
public string License;
///
/// 所属するパッケージリスト名称
///
public string PackageListName;
}
///
/// パッケージ参照を示すクラス
///
public struct Entry
{
///
/// パッケージ名
///
[XmlAttribute]
public string Name;
///
/// パッケージのバージョン比較の式
///
[XmlAttribute]
public string Flags;
///
/// パッケージのバージョン
///
[XmlAttribute]
public string Version;
public Entry(string name, string flags, string version)
{
Name = name;
Flags = flags;
Version = version;
}
public bool Match(Package pkg)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(
(System.Text.RegularExpressions.Regex.IsMatch(Name, "^/.*/$"))?
Name.Substring(1, Name.Length-2) :
string.Format("^{0}$", System.Text.RegularExpressions.Regex.Escape(Name))
, System.Text.RegularExpressions.RegexOptions.Singleline);
if (regex.IsMatch(pkg.Name)) {
if (string.IsNullOrEmpty(Version)) {
return true;
} else {
// TODO Flagの内容は現在のところ無視
return pkg.Version == Version;
}
} else {
return false;
}
}
}
public class Installer
{
///
/// コンストラクタ
///
public Installer()
{
}
public Platform Platform;
///
/// ダウンロードリソースURLの配列
///
public LocationEntry Url;
///
/// ファイル検証用ハッシュ
///
[XmlElement]
public HashValue[] Hash;
}
///
/// リソースの位置を示すクラス
///
public sealed class LocationEntry
{
///
/// コンストラクタ
///
public LocationEntry()
{
}
///
/// コンストラクタ
///
/// リソースのURL
public LocationEntry(string sHref)
{
Href = sHref;
}
///
/// リソースのURL
///
[XmlAttribute]
public string Href;
}
}