OSDN Git Service

AppliStation-GUI,r899のコミットしわすれ
[applistation/AppliStation.git] / na-get-lib / NaGet.Packages.Install / InstalledPackage.cs
1 using System;\r
2 using System.IO;\r
3 using System.Collections.Generic;\r
4 using System.Xml.Serialization;\r
5 using System.Text.RegularExpressions;\r
6 using NaGet.Packages;\r
7 \r
8 namespace NaGet.Packages.Install\r
9 {       \r
10         public class InstalledPackage : Package\r
11         {\r
12                 /// <summary>\r
13                 /// アンインストール情報\r
14                 /// </summary>\r
15                 public UninstallInformation UninstallInfo;\r
16                 \r
17                 public static InstalledPackage PackageConverter(Package basePkg) \r
18                 {\r
19                         InstalledPackage pkg = new InstalledPackage();\r
20                         \r
21                         NaGet.Utils.FieldCopy(basePkg, ref pkg);\r
22                         pkg.UninstallInfo = UninstallInformation.NewInstance(basePkg);\r
23                         \r
24                         return pkg;\r
25                 }\r
26                 \r
27                 public static InstalledPackage PackageConverter(Package basePkg, UninstallInformation info)\r
28                 {\r
29                         InstalledPackage instPkg = new InstalledPackage();\r
30                         \r
31                         NaGet.Utils.FieldCopy(basePkg, ref instPkg);\r
32                         instPkg.UninstallInfo = info;\r
33                         \r
34                         Match match = Regex.Match(info.DisplayName, basePkg.UninstallerKey);\r
35                         if (! match.Success) {\r
36                                 throw new ArgumentException(string.Format("{0}({1}) does not matched for {2}.", basePkg.Name, basePkg.Version, info.DisplayName));\r
37                         } else if (match.Groups[1].Success) { // DisplayNameの方のバージョン表記を優先\r
38                                 instPkg.Version = match.Groups[1].Value;\r
39                         } else if (! string.IsNullOrEmpty(info.DisplayVersion) ) {\r
40                                 instPkg.Version = info.DisplayVersion;\r
41                         } else {\r
42                                 instPkg.Version = string.Empty;\r
43                         }\r
44                         \r
45                         return instPkg;\r
46                 }\r
47         }\r
48 }\r