예제 #1
0
        private void MigrateCacheDir()
        {
            int version = CacheVersion;

            if (version == CUR_VERSION)
            {
                return;
            }

            var legacy_root_path = CoverArtSpec.LegacyRootPath;

            if (version < 1)
            {
                string legacy_artwork_path = Paths.Combine(LegacyPaths.ApplicationData, "covers");

                if (!Directory.Exists(legacy_root_path))
                {
                    Directory.Create(legacy_root_path);

                    if (Directory.Exists(legacy_artwork_path))
                    {
                        Directory.Move(new SafeUri(legacy_artwork_path), new SafeUri(legacy_root_path));
                    }
                }

                if (Directory.Exists(legacy_artwork_path))
                {
                    Log.InformationFormat("Deleting old (Banshee < 1.0) artwork cache directory {0}", legacy_artwork_path);
                    Directory.Delete(legacy_artwork_path, true);
                }
            }

            if (version < 2)
            {
                int deleted = 0;
                foreach (string dir in Directory.GetDirectories(legacy_root_path))
                {
                    int    size;
                    string dirname = System.IO.Path.GetFileName(dir);
                    if (Int32.TryParse(dirname, out size) && !IsCachedSize(size))
                    {
                        Directory.Delete(dir, true);
                        deleted++;
                    }
                }

                if (deleted > 0)
                {
                    Log.InformationFormat("Deleted {0} extraneous album-art cache directories", deleted);
                }
            }

            if (version < 3)
            {
                Log.Information("Migrating album-art cache directory");
                var started = DateTime.Now;
                int count   = 0;

                var root_path = CoverArtSpec.RootPath;
                if (!Directory.Exists(root_path))
                {
                    Directory.Create(root_path);
                }

                string sql = "SELECT Title, ArtistName FROM CoreAlbums";
                using (var reader = new HyenaDataReader(ServiceManager.DbConnection.Query(sql))) {
                    while (reader.Read())
                    {
                        var album    = reader.Get <string>(0);
                        var artist   = reader.Get <string>(1);
                        var old_file = CoverArtSpec.CreateLegacyArtistAlbumId(artist, album);
                        var new_file = CoverArtSpec.CreateArtistAlbumId(artist, album);

                        if (String.IsNullOrEmpty(old_file) || String.IsNullOrEmpty(new_file))
                        {
                            continue;
                        }

                        old_file = String.Format("{0}.jpg", old_file);
                        new_file = String.Format("{0}.jpg", new_file);

                        var old_path = new SafeUri(Paths.Combine(legacy_root_path, old_file));
                        var new_path = new SafeUri(Paths.Combine(root_path, new_file));

                        if (Banshee.IO.File.Exists(old_path) && !Banshee.IO.File.Exists(new_path))
                        {
                            Banshee.IO.File.Move(old_path, new_path);
                            count++;
                        }
                    }
                }

                if (ServiceManager.DbConnection.TableExists("PodcastSyndications"))
                {
                    sql = "SELECT Title FROM PodcastSyndications";
                    foreach (var title in ServiceManager.DbConnection.QueryEnumerable <string> (sql))
                    {
                        var old_digest = CoverArtSpec.LegacyEscapePart(title);
                        var new_digest = CoverArtSpec.Digest(title);

                        if (String.IsNullOrEmpty(old_digest) || String.IsNullOrEmpty(new_digest))
                        {
                            continue;
                        }

                        var old_file = String.Format("podcast-{0}.jpg", old_digest);
                        var new_file = String.Format("podcast-{0}.jpg", new_digest);

                        var old_path = new SafeUri(Paths.Combine(legacy_root_path, old_file));
                        var new_path = new SafeUri(Paths.Combine(root_path, new_file));

                        if (Banshee.IO.File.Exists(old_path) && !Banshee.IO.File.Exists(new_path))
                        {
                            Banshee.IO.File.Move(old_path, new_path);
                            count++;
                        }
                    }
                }

                if (count == 0)
                {
                    ResetScanResultCache();
                }

                Directory.Delete(legacy_root_path, true);
                Log.InformationFormat("Migrated {0} files in {1}s", count, DateTime.Now.Subtract(started).TotalSeconds);
            }

            CacheVersion = CUR_VERSION;
        }
예제 #2
0
 private void AssertDigested(string original, string expected)
 {
     Assert.AreEqual(expected, CoverArtSpec.Digest(original));
 }