/// <summary>
        // Returns a specific Volume object, but preassigns properties of the Volume baseclass only.
        // Filling properties of the specific, derived object, is job of the specific VolumeScanner implementation.
        /// </summary>
        private static TVolume CreateVolumeObject(PlatformIO.DriveInfo d,
                                                  VolumeDatabase database,
                                                  bool isHashed)
        {
            // TODO : check here whether everything is still filled correctly after media class reorganisation

            long volumeID = VolumeDatabase.ID_NONE;

            if (database != null)
            {
                // TODO : this is neither threadsave nor multi-instance save in general!
                // maybe the db (physical db, VolumeDatabase object? this scanner?) should be locked during scanning?
                volumeID = database.GetNextVolumeID();
            }

            TVolume v = CreateInstance <TVolume>(database);

//			  /* v = new TVolume(database); */
//			  v = (TVolume)VolumeDB.Volume.CreateInstance(volumeType, database);
//
            // initialize fields of the Volume base class.
            // don't initialize via properties. initializing via properties is error-prone
            // as the compiler won't error if a new field is added to the base class
            // and forgotten to be initialized here.
            v.SetVolumeFields(
                volumeID,
                d.IsMounted ? d.VolumeLabel : string.Empty,
                DateTime.Now,
                /*di.VolumeSerialNumber,*/
                isHashed,
                volumeID.ToString(),
                d.DriveType.ToVolumeDriveType(),
                null,
                DateTime.MinValue,
                DateTime.MinValue,
                null,
                null,
                null
                );

            return(v);
        }
Exemple #2
0
        internal override void ImportThreadMain(string sourceDbPath,
		                                         VolumeDatabase targetDb,
		                                         string dbDataPath,
		                                         BufferedVolumeItemWriter writer)
        {
            string thumbsPath = sourceDbPath + "_thumbs";

            string sqlDisks = "SELECT * FROM disks ORDER BY id";
            string sqlFiles = "SELECT * FROM files WHERE iddisk = {0} ORDER BY iddisk, id";

            using (IDbConnection conn = SqliteDB.Open(sourceDbPath, false)) {

                long totalFiles = CountFiles(conn);
                long fileCounter = 0;

                using (IDbCommand cmdDisks = conn.CreateCommand()) {
                    using (IDbCommand cmdFiles = conn.CreateCommand()) {

                        cmdDisks.CommandText = sqlDisks;

                        using (IDataReader readerDisks = cmdDisks.ExecuteReader()) {
                            while (readerDisks.Read()) {
                                long diskID = (long)readerDisks["id"];
                                long minFileID = GetMinFileID(conn, diskID);
                                string rootPath = "file://" + (string)readerDisks["root"];
                                long volumeID = targetDb.GetNextVolumeID();
                                long[] counters = { 0L, 0L, 0L };

                                string volDBThumbsPath = CreateThumbsDir(dbDataPath, volumeID);

                                cmdFiles.CommandText = string.Format(sqlFiles, diskID);

                                using (IDataReader readerFiles = cmdFiles.ExecuteReader()) {
                                    while (readerFiles.Read()) {
                                        long fileID = (long)readerFiles["id"];

                                        ImportFile(readerFiles,
                                                   volumeID,
                                                   minFileID,
                                                   rootPath,
                                                   ConvertMetaData(conn, fileID),
                                                   targetDb,
                                                   writer,
                                                   counters);

                                        ImportThumb(fileID,
                                                    (2 + fileID - minFileID),
                                                    thumbsPath,
                                                    volDBThumbsPath);

                                        PostProgressUpdate((++fileCounter * 100.0) / totalFiles);
                                        CheckForCancellationRequest();
                                    }
                                }

                                ImportDisk(readerDisks,
                                           volumeID,
                                           targetDb,
                                           counters);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void RecursiveDump(XmlNode node,
                                   long volumeID,
                                   long parentID,
                                   ref string comment,
                                   ref string borrow,
                                   ref MetadataStore metadata)
        {
            long          dirID = 0L;
            string        b = null, c = null;
            MetadataStore md = MetadataStore.Empty;

            CheckForCancellationRequest();

            switch (node.Name)
            {
            case "catalog":
                mediaCounter = 0;
                totalMedia   = GetMediaCount(node);
                break;

            case "media":
                volumeID  = targetDb.GetNextVolumeID();
                dirID     = 1L;                     // root item
                idCounter = 2L;                     // id 1 is the root item
                //path.Clear();
                for (int i = 0; i < counters.Length; i++)
                {
                    counters[i] = 0L;
                }
                break;

            case "directory":
                dirID = idCounter++;
                path.Push(node.Attributes["name"].Value);
                break;
            }

            foreach (XmlNode n in node)
            {
                RecursiveDump(n, volumeID, dirID, ref c, ref b, ref md);
            }

            switch (node.Name)
            {
            case "media":
                ImportMedia(node, b, c, volumeID);
                PostProgressUpdate((++mediaCounter * 100.0) / totalMedia);
                break;

            case "directory":
                path.Pop();
                ImportFile(node, c, volumeID, parentID, dirID, path,
                           /* ignore weird CdCat directory metadata */ MetadataStore.Empty);
                break;

            case "file":
                ImportFile(node, c, volumeID, parentID, idCounter++, path, md);
                break;

            case "comment":
                if (!ConvertMetaData(node, ref metadata))
                {
                    comment = node.InnerText.Trim();
                }
                break;

            case "borrow":
                borrow = node.InnerText.Trim();
                break;

            case "mp3tag":
                ConvertMetaData(node, ref metadata);
                break;

            case "datafile":
                if (float.Parse(node.Attributes["version"].Value, ci.NumberFormat) > MAX_SUPPORTED_VERSION)
                {
                    throw new ImportException("Unsupported catalog version");
                }
                break;
            }
        }
Exemple #4
0
        internal override void ImportThreadMain(string sourceDbPath,
                                                VolumeDatabase targetDb,
                                                string dbDataPath,
                                                BufferedVolumeItemWriter writer)
        {
            string thumbsPath = sourceDbPath + "_thumbs";

            string sqlDisks = "SELECT * FROM disks ORDER BY id";
            string sqlFiles = "SELECT * FROM files WHERE iddisk = {0} ORDER BY iddisk, id";

            using (IDbConnection conn = SqliteDB.Open(sourceDbPath, false)) {
                long totalFiles  = CountFiles(conn);
                long fileCounter = 0;

                using (IDbCommand cmdDisks = conn.CreateCommand()) {
                    using (IDbCommand cmdFiles = conn.CreateCommand()) {
                        cmdDisks.CommandText = sqlDisks;

                        using (IDataReader readerDisks = cmdDisks.ExecuteReader()) {
                            while (readerDisks.Read())
                            {
                                long   diskID    = (long)readerDisks["id"];
                                long   minFileID = GetMinFileID(conn, diskID);
                                string rootPath  = "file://" + (string)readerDisks["root"];
                                long   volumeID  = targetDb.GetNextVolumeID();
                                long[] counters  = { 0L, 0L, 0L };

                                string volDBThumbsPath = CreateThumbsDir(dbDataPath, volumeID);

                                cmdFiles.CommandText = string.Format(sqlFiles, diskID);

                                using (IDataReader readerFiles = cmdFiles.ExecuteReader()) {
                                    while (readerFiles.Read())
                                    {
                                        long fileID = (long)readerFiles["id"];

                                        ImportFile(readerFiles,
                                                   volumeID,
                                                   minFileID,
                                                   rootPath,
                                                   ConvertMetaData(conn, fileID),
                                                   targetDb,
                                                   writer,
                                                   counters);

                                        ImportThumb(fileID,
                                                    (2 + fileID - minFileID),
                                                    thumbsPath,
                                                    volDBThumbsPath);

                                        PostProgressUpdate((++fileCounter * 100.0) / totalFiles);
                                        CheckForCancellationRequest();
                                    }
                                }

                                ImportDisk(readerDisks,
                                           volumeID,
                                           targetDb,
                                           counters);
                            }
                        }
                    }
                }
            }
        }