Exemple #1
0
        static private int SetFiles(string path)
        {
            path = ImageSearch.GetDirectory(path);
            List <string> files = new List <string>();

            files.AddRange(Directory.GetFiles(path, "*.png", SearchOption.AllDirectories));
            files.AddRange(Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories));
            files.AddRange(Directory.GetFiles(path, "*.gif", SearchOption.AllDirectories));
            Console.WriteLine(files.Count + " files.");
            int count = 0;

            foreach (var f in files)
            {
                var fi = new FileInfo(f);
                if (fi.Length > 0)
                {
                    string img = _iv.AddImage(f);

                    count++;
                    if (count % 1000 == 0)
                    {
                        Console.WriteLine("\r {0}/{1} {2}", count, files.Count, f);
                    }
                }
            }
            return(files.Count);
        }
Exemple #2
0
        static void CreateDb(string path)
        {
            path = ImageSearch.GetDirectory(path);

            List <string> files = new List <string>();

            FindFiles(path, "*.jpg", files);
            List <ImageInfo> info = new List <ImageInfo>();

            Console.WriteLine("Indexing {0} items...", files.Count);
            string sp = Path.DirectorySeparatorChar.ToString();

            foreach (var f in files)
            {
                string   hashStr  = f.Substring(path.Length, 3 * 8 - 1).Replace(sp, "");
                string   filename = Path.GetFileNameWithoutExtension(f);
                string[] data     = filename.Split('_');

                UInt64 hash      = Convert.ToUInt64(hashStr, 16);
                UInt16 titleId   = Convert.ToUInt16(data[0]);
                UInt16 episodeId = Convert.ToUInt16(data[1]);
                UInt32 frame     = Convert.ToUInt32(data[2]);

                info.Add(new ImageInfo
                {
                    Hash      = hash,
                    TitleId   = titleId,
                    EpisodeId = episodeId,
                    Frame     = frame
                });
            }

            Console.WriteLine("Sorting...");
            var sortedInfo = info.OrderBy(c => c.Hash).ThenBy(c => c.TitleId).ThenBy(c => c.EpisodeId).ThenBy(c => c.Frame);

            using (FileStream fs = new FileStream("index.db", FileMode.Create, FileAccess.Write))
            {
                // .gz 形式で圧縮
                using (GZipStream gzipStream = new GZipStream(fs, CompressionMode.Compress))
                {
                    using (BinaryWriter bw = new BinaryWriter(gzipStream))
                    {
                        bw.Write(sortedInfo.Count());
                        foreach (var w in sortedInfo)
                        {
                            bw.Write(w.Hash);
                            bw.Write(w.TitleId);
                            bw.Write(w.EpisodeId);
                            bw.Write(w.Frame);
                        }
                    }
                }
            }
            Console.WriteLine("Finished.");
        }