Пример #1
0
        public static Dictionary<string, PMetaData> LoadCache(string folderPath)
        {
            Dictionary<string, PMetaData> CacheResult = new Dictionary<string, PMetaData>();

            if (System.IO.File.Exists(folderPath + @"\" + GENTLE_FILE ))
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(folderPath + @"\" +GENTLE_FILE))
                {
                    string line;
                    string filepath = null;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line[0] == '[')
                        {
                            int index = line.IndexOf(']');
                            filepath = folderPath + @"\" + line.Substring(1, index - 1);
                            CacheResult[filepath] = new PMetaData();
                        }
                        else if (line.Contains("="))
                        {
                            var values = line.Split('=');
                            string field = values[0].Trim().ToLower();
                            string fieldvalue = values[1].Trim().ToLower();

                            if(field == "hash") {
                                if (fieldvalue.Length == 40)
                                    CacheResult[filepath].Hash = fieldvalue;
                            }                            
                            else if (line.Substring(0, 8) == "keywords")
                            {
                                CacheResult[filepath].Keywords = new List<string>(line.Substring(9).Split(','));
                            }
                            else if (line.Substring(0, 7) == "updated")
                            {
                                try
                                {
                                    CacheResult[filepath].Updated = Convert.ToInt64(line.Substring(8));
                                }
                                catch
                                {
                                    
                                }
                            }
                        }
                    }
                    reader.Close();
                }
            }
            return CacheResult;
        }
Пример #2
0
        public static Dictionary<string, PMetaData> LoadCache(string folderPath)
        {
            Dictionary<string, PMetaData> CacheResult = new Dictionary<string, PMetaData>();

            if (System.IO.File.Exists(folderPath + @"\" + PICASA_FILE))
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(folderPath + @"\" + PICASA_FILE))
                {
                    string line;
                    string filepath = null;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line[0] == '[')
                        {
                            filepath = folderPath + @"\" + line.Substring(1, line.IndexOf(']') - 1);
                            CacheResult[filepath] = new PMetaData();
                        }
                        else if (line.Substring(0, 8) == "keywords")
                        {
                            var ptags = new List<string>(line.Substring(9).Split(','));
                            ptags = ptags.ConvertAll(a => a.Trim());

                            CacheResult[filepath].Keywords.AddRange(ptags);
                        }
                        else
                        {
                            if (line.Contains("="))
                            {
                                int index = line.IndexOf('=');
                                CacheResult[filepath].RawData[line.Substring(0, index)] = line.Substring(index + 1);
                            }
                        }
                    }

                }
            }
            return CacheResult;
        }
Пример #3
0
        public Dictionary<string, PMetaData> ScanFolder(string folder)
        {
            Dictionary<string, PMetaData> Results = new Dictionary<string,PMetaData>();
            Dictionary<string, PMetaData> DataFromPicasa = PicasaHelper.LoadCache(folder);
            Dictionary<string, PMetaData> DataFromGentleman = GHelper.LoadCache(folder);
            int index = 0;
            foreach (var filepath in System.IO.Directory.GetFiles(folder))
            {
                string ext = System.IO.Path.GetExtension(filepath).ToLower();

                if (!SupportFileExt.Contains(ext)) continue;
                index += 1;
                Results[filepath] = new PMetaData();
                Results[filepath].FilePath = filepath;
                Results[filepath].Updated = System.IO.File.GetLastWriteTimeUtc(filepath).Ticks;

                // FolderKeywords
                var folderpaths = folder.Split('\\');
                List<string> folderkeywords = new List<string>();
                if(folderpaths.Length > 3) {
                    folderkeywords.Add("#" + folderpaths[folderpaths.Length - 1]);
                    folderkeywords.Add("#" + folderpaths[folderpaths.Length - 2]);
                }

                // Copy Keywords and RawData from Picasa
                if (DataFromPicasa.ContainsKey(filepath))
                {
                    Results[filepath].Keywords = DataFromPicasa[filepath].Keywords;
                    Results[filepath].RawData = DataFromPicasa[filepath].RawData;
                }

                // Update Keywords from image Raw Data
                if ((ext == ".jpg" || ext ==".jpeg") && (!DataFromGentleman.ContainsKey(filepath)
                    || DataFromGentleman[filepath].Updated != Results[filepath].Updated))
                {
                    try
                    {
                        JpegHelper p = new JpegHelper(filepath);
                        Results[filepath].Keywords.AddRange(p.Keywords);
                    }
                    catch { }
                    // Update Path Keywords     
                    Results[filepath].Keywords.AddRange(folderkeywords);
                }
                if (DataFromGentleman.ContainsKey(filepath) && DataFromGentleman[filepath].Hash != null)
                {
                    Results[filepath].Hash = DataFromGentleman[filepath].Hash;
                }
                else
                {
                    try
                    {
                        Results[filepath].Hash = ThumbHelper.ComputeHash(filepath);
                    }
                    catch
                    {
                        Results.Remove(filepath);
                        continue;
                    }
                }

                Results[filepath].Keywords = Algorithm.TagSet(Results[filepath].Keywords);
                Results[filepath].Hash = Results[filepath].Hash.ToUpper();
            }
            return Results;
        }