OSDN Git Service

AppliStation,全部のバージョン表記を1.2.1にしたりした。また、win7がwin2008と間違って認識するバグの修正
[applistation/AppliStation.git] / archive-inst / InstalledFileList.cs
1 using System;\r
2 using System.Xml.Serialization;\r
3 using System.Collections.Generic;\r
4 using System.IO;\r
5 using NaGet.Packages;\r
6 \r
7 namespace ArchiveInstall\r
8 {\r
9         public class InstalledFileList\r
10         {\r
11                 [XmlElement("Entry")]\r
12                 public List<InstalledFile> Entries;\r
13                 \r
14                 public InstalledFileList()\r
15                 {\r
16                         Entries = new List<InstalledFile>();\r
17                 }\r
18                 \r
19                 /// <summary>\r
20                 /// \83n\83b\83V\83\85\8c\9f\8fØ\82ð\8ds\82¢\81A\95Ï\8dX\82³\82ê\82½\82Æ\8am\94F\82µ\82½(\91Ã\93\96\82Å\82È\82¢)\83t\83@\83C\83\8b\82ð\95Ô\82·\r
21                 /// </summary>\r
22                 /// <param name="rootDirectory">\8c\9f\8d¸\82·\82é\83t\83@\83C\83\8b\82Ì\83\8b\81[\83g\83f\83B\83\8c\83N\83g\83\8a</param>\r
23                 /// <returns>\95Ï\8dX\82³\82ê\82½\82Æ\8c\9f\8fo\82µ\82½\83t\83@\83C\83\8b()</returns>\r
24                 public IEnumerable<InstalledFile> Verify(string rootDirectory)\r
25                 {\r
26                         foreach (InstalledFile file in Entries) {\r
27                                 if (! file.Hash.Validate(Path.Combine(rootDirectory, file.Path)) ) {\r
28                                         yield return file;\r
29                                 }\r
30                         }\r
31                 }\r
32                 \r
33                 public static InstalledFileList CreateFromFiles(string rootDirectory)\r
34                 {\r
35                         InstalledFileList list = new InstalledFileList();\r
36                         foreach (string filepath in Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories)) {\r
37                                 string relativePath = NaGet.Utils.GetRelativePath(rootDirectory, filepath);\r
38                                 if (relativePath.StartsWith(".applistation.")) {\r
39                                         continue;\r
40                                 }\r
41                                 \r
42                                 InstalledFile file = new InstalledFile();\r
43                                 file.Path = relativePath;\r
44                                 file.Hash = new HashValue();\r
45                                 file.Hash.Type = HashValueType.SHA1SUM;\r
46                                 file.Hash.Value = HashValue.HashValueFor(filepath, file.Hash.Type);\r
47                                 \r
48                                 list.Entries.Add(file);\r
49                         }\r
50                         return list;\r
51                 }\r
52         }\r
53         \r
54         public class InstalledFile\r
55         {\r
56                 /// <summary>\r
57                 /// \83t\83@\83C\83\8b\82Ì\83p\83X\r
58                 /// </summary>\r
59                 public string Path;\r
60                 \r
61                 /// <summary>\r
62                 /// \83n\83b\83V\83\85\92l\r
63                 /// </summary>\r
64                 public HashValue Hash;\r
65                 \r
66                 public InstalledFile()\r
67                 {\r
68                 }\r
69         }\r
70 }\r