示例#1
0
 private void loadFolder(object param_obj)
 {
     Tuple<string, ThumbnailView> param = (Tuple<string, ThumbnailView>)param_obj;
     IEnumerable<string> paths = Directory.EnumerateFiles(param.Item1, "*", SearchOption.AllDirectories);
     int loaded = 0;
     foreach (string path in paths)
     {
         lock (m_loadOperationsStarted)
         {
             if (m_loadOperationsStarted.Contains(path))
             {
                 continue;
             }
             else
             {
                 m_loadOperationsStarted.Add(path);
             }
         }
         lock (m_loaded)
         {
             if (m_loaded.ContainsKey(path))
             {
                 param.Item2.Add(m_loaded[path]);
                 continue;
             }
         }
         if (pathIsImageFile(path))
         {
             ImageItem loadedItem = new ImageItem(path, this);
             try
             {
                 loadedItem.GenerateThumb(256, 256);
             }
             catch (Exception ex)
             {
                 loadedItem = null;
             }
             if (loadedItem != null)
             {
                 if (param.Item2 != null)
                 {
                     param.Item2.Add(loadedItem); //ThumbnailView.Add is thread-safe.
                 }
                 lock (m_loaded)
                 {
                     m_loaded.Add(path, loadedItem);
                 }
                 loaded++;
             }
         }
     }
 }
示例#2
0
        private void loadDB(object param)
        {
            string path = ((Tuple<string, ThumbnailView>)param).Item1;
            ThumbnailView container = ((Tuple<string, ThumbnailView>)param).Item2;

            Environment.CurrentDirectory = Path.GetDirectoryName(path);

            SQLiteConnection cnn = new SQLiteConnection("Data Source=" + path);
            cnn.Open();

            DateTime start = DateTime.Now;

            using (SQLiteCommand select = new SQLiteCommand("SELECT * FROM Media", cnn))
            {
                SQLiteDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    string filePath = Path.GetFullPath((string)reader["path"]);

                    if (!File.Exists(filePath))
                    {
                        continue;
                    }

                    MediaItem item = new ImageItem(filePath, this);

                    item.loadThumbFromJpeg((byte[])reader["thumb"]);

                    string[] tags = ((string)reader["tags"]).Split(';');
                    foreach (string tag in tags)
                    {
                        if (tag.Length == 0)
                        {
                            continue;
                        }
                        item.addTag(tag);
                    }

                    string[] attributes = ((string)reader["attributes"]).Split(';');
                    if (attributes.Length > 1)
                    {
                        foreach (string attribute in attributes)
                        {
                            if (attribute.Length == 0)
                            {
                                continue;
                            }
                            string[] attribute_components = attribute.Split(':');
                            string[] attribute_values = attribute_components[1].Split(',');
                            foreach (string value in attribute_values)
                            {
                                if (!hasAttribute(attribute_components[0]))
                                {
                                    addAttribute(attribute_components[0]);
                                }
                                item.appendAttribute(attribute_components[0], value);
                            }
                        }
                    }
                    m_loaded.Add(filePath, item);
                    container.Add(item);
                }
            }

            MessageBox.Show((DateTime.Now - start).ToString());
            
            cnn.Close();
        }