Example #1
0
        // オリジナルのファイル名を尊重しつつサマリーを付加する.
        public static string ZipName(string name)
        {
            string node = Path.GetFileNameWithoutExtension(name);

            // ファイル名がnode名だけだった場合.
            if (TDCGExplorer.Arcsnames.ContainsKey(node) == true)
            {
                char[]         illegal = { '/', '\\', '*', ':', '?', '<', '>', '\"', '|' };
                ArcsNamesEntry entry   = TDCGExplorer.Arcsnames[node];
                string         summary = entry.summary;
                foreach (char illeagalchar in illegal)
                {
                    summary = summary.Replace(illeagalchar, ' ');
                }
                node = node + " " + summary;
            }
            return(node);
        }
Example #2
0
        // arcsnames.zipを解凍、展開する.
        public void GetArcNamesZipInfo()
        {
            try
            {
                string localfile = zipArcLocalName();
                string arcname   = "tmp/arcnames.txt";

                // ZIPファイルを展開する.
                IArchive arc = new ZipArchive();
                arc.Open(localfile);
                if (arc == null)
                {
                    return;
                }

                foreach (IArchiveEntry entry in arc)
                {
                    if (entry.FileName == arcname)
                    {
                        arcsNames.Clear();
                        using (MemoryStream ms = new MemoryStream((int)entry.Size))
                        {
                            arc.Extract(entry, ms);
                            ms.Seek(0, SeekOrigin.Begin);
                            StreamReader reader = new StreamReader(ms, System.Text.Encoding.GetEncoding("Shift_JIS"));
                            Regex        regCsv = new System.Text.RegularExpressions.Regex("\\s*(\"(?:[^\"]|\"\")*\"|[^,]*)\\s*,\\s*(\"(?:[^\"]|\"\")*\"|[^,]*)\\s*,\\s*(\"(?:[^\"]|\"\")*\"|[^,]*)\\s*,\\s*(\"(?:[^\"]|\"\")*\"|[^,]*)\\s*", RegexOptions.None);

                            // CSVファイルを展開してarcsNamesを構築する.
                            for (; ;)
                            {
                                string line = reader.ReadLine();
                                if (line == null)
                                {
                                    break;
                                }
                                Match          m        = regCsv.Match(line);
                                ArcsNamesEntry arcentry = new ArcsNamesEntry();
                                while (m.Success)
                                {
                                    for (int index = 1; index < 5; index++)
                                    {
                                        string field = m.Groups[index].Value;
                                        if (field == "\\N")
                                        {
                                            field = "";
                                        }
                                        field = field.Trim();
                                        if (field.StartsWith("\"") && field.EndsWith("\""))
                                        {
                                            field = field.Substring(1, field.Length - 2);
                                            field = field.Replace("\"\"", "\"");
                                        }
                                        switch (index)
                                        {
                                        case 1:
                                            arcentry.code = field;
                                            break;

                                        case 2:
                                            arcentry.location = field;
                                            break;

                                        case 3:
                                            arcentry.summary = field;
                                            break;

                                        case 4:
                                            arcentry.origname = field;
                                            break;
                                        }
                                    }
                                    m = m.NextMatch();
                                }
                                if (arcsNames.ContainsKey(arcentry.code) == false)
                                {
                                    arcsNames[arcentry.code] = arcentry;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                TDCGExplorer.SetToolTips("Error GetArcNamesZipInfo : " + e.Message);
            }
        }