OSDN Git Service

na-get-lib,ファイルダウンロードで attachment;filename= のようにセミコロン後にスペースがない場合の対応
[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                                 string filepath = Path.Combine(rootDirectory, file.Path);\r
28                                 \r
29                                 if (File.Exists(filepath) && (! file.Hash.Validate(filepath))) {\r
30                                         yield return file;\r
31                                 }\r
32                         }\r
33                 }\r
34                 \r
35                 public static InstalledFileList CreateFromFiles(string rootDirectory)\r
36                 {\r
37                         InstalledFileList list = new InstalledFileList();\r
38                         foreach (string filepath in Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories)) {\r
39                                 string relativePath = NaGet.Utils.GetRelativePath(rootDirectory, filepath);\r
40                                 if (relativePath.StartsWith(".applistation.")) {\r
41                                         continue;\r
42                                 }\r
43                                 \r
44                                 InstalledFile file = new InstalledFile();\r
45                                 file.Path = relativePath;\r
46                                 file.Hash = new HashValue();\r
47                                 file.Hash.Type = HashValueType.SHA1SUM;\r
48                                 file.Hash.Value = HashValue.HashValueFor(filepath, file.Hash.Type);\r
49                                 \r
50                                 list.Entries.Add(file);\r
51                         }\r
52                         return list;\r
53                 }\r
54         }\r
55         \r
56         public class InstalledFile\r
57         {\r
58                 /// <summary>\r
59                 /// \83t\83@\83C\83\8b\82Ì\83p\83X\r
60                 /// </summary>\r
61                 public string Path;\r
62                 \r
63                 /// <summary>\r
64                 /// \83n\83b\83V\83\85\92l\r
65                 /// </summary>\r
66                 public HashValue Hash;\r
67                 \r
68                 public InstalledFile()\r
69                 {\r
70                 }\r
71         }\r
72 }\r