Ejemplo n.º 1
0
        private static VolumeDatabase ReadData(SQLiteConnection conn)
        {
            // Track all folders by db-id for fast lookup
            _foldHash  = new Hashtable();
            _lfoldHash = new Hashtable();
            _fileHash  = new Hashtable();

            VolumeDatabase mem = new VolumeDatabase();

            string txt = "select * from Discs";

            using (SQLiteCommand cmd = new SQLiteCommand(txt, conn))
            {
                using (SQLiteDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        var dbid = (long)rdr["ID"];  // The top folder has this as the owner id

                        DiscInDatabase did = new DiscInDatabase(-(int)dbid);

                        did.DriveFormat      = rdr["Format"] as string;
                        did.DriveType        = (DriveType)((long)rdr["Type"]);
                        did.TotalFreeSpace   = (long)rdr["Free"];
                        did.TotalSize        = (long)rdr["Size"];
                        did.Scanned          = DateTime.Parse((string)rdr["ScanTime"]);
                        did.SerialNumber     = rdr["Serial"] as string;
                        did.PhysicalLocation = rdr["PhysicalLocation"] as string;
                        did.FromDrive        = rdr["FromDrive"] as string;
                        did.Name             = rdr.GetString(10);
                        did.Keywords         = rdr.GetString(11);
                        did.Flags            = rdr.GetInt32(12);
                        did.Description      = rdr.GetString(13);
                        did.ClusterSize      = (uint)rdr.GetInt32(14);

                        mem.AddDisc(did);
                        _foldHash.Add(-(int)dbid, did);
                    }
                }
            }

            foreach (var discInDatabase in mem.GetDiscs())
            {
                ReadFolders(conn, discInDatabase);
            }

            ReadAllFiles(conn, mem);

            ReadLogicalFolders(conn, mem);
            ReadLogicalFolderItems(conn, mem);

            _lfoldHash = _fileHash = _foldHash = null; // GC
            return(mem);
        }
Ejemplo n.º 2
0
 private void updateLastScannedInfo()
 {
     if (cbReplace.Checked && (cbDiscToReplace.Items.Count > 0))
     {
         cbDiscToReplace.Enabled = true;
         DiscInDatabase discToReplace = cbDiscToReplace.SelectedItem as DiscInDatabase;
         if (discToReplace != null)
         {
             llScanned.Text     = discToReplace.Scanned.ToString();
             llLastOptions.Text = discToReplace.GetOptionsDescription();
             if (string.IsNullOrEmpty(discToReplace.FromDrive))
             {
                 llLastDrive.Text      = Properties.Resources.NoDrive;
                 llLastDrive.ForeColor = Color.Black;
             }
             else
             {
                 llLastDrive.Text = discToReplace.FromDrive;
                 if (discToReplace.FromDrive.ToLower() != readFromDrive.ToLower())
                 {
                     llLastDrive.ForeColor = Color.Red;
                 }
                 else
                 {
                     llLastDrive.ForeColor = Color.Black;
                 }
             }
             tbUserLabel.Text    = discToReplace.Name;
             tbUserLabel.Enabled = false;
         }
     }
     else
     {
         llScanned.Text          = "(not scanned)";
         llLastOptions.Text      = "(none)";
         llLastDrive.Text        = Properties.Resources.NoDrive;
         llLastDrive.ForeColor   = Color.Black;
         cbDiscToReplace.Enabled = false;
         tbUserLabel.Enabled     = true;
     }
 }
Ejemplo n.º 3
0
 public DlgDiscProperties(DiscInDatabase discInDatabase)
     : this()
 {
     this.discInDatabase = discInDatabase;
     tbUserLabel.Text    = discInDatabase.Name;
     if (string.IsNullOrEmpty(discInDatabase.VolumeLabel))
     {
         llVolumeLabel.Text = Properties.Resources.NoLabel;
     }
     else
     {
         llVolumeLabel.Text = discInDatabase.VolumeLabel;
     }
     llDriveFormat.Text      = discInDatabase.DriveFormat;
     llDriveType.Text        = discInDatabase.DriveType.ToString();
     llFreeSpace.Text        = discInDatabase.TotalFreeSpace.ToKBAndB();
     llSize.Text             = discInDatabase.TotalSize.ToKBAndB();
     tbKeywords.Text         = discInDatabase.Keywords;
     tbPhysicalLocation.Text = discInDatabase.PhysicalLocation;
     tbDescription.Text      = discInDatabase.Description;
     llScanned.Text          = discInDatabase.Scanned.ToString();
     llLastOptions.Text      = discInDatabase.GetOptionsDescription();
     llSerialNumber.Text     = discInDatabase.SerialNumber;
     if (string.IsNullOrEmpty(discInDatabase.FromDrive))
     {
         llDriveName.Text = Properties.Resources.NoDrive;
     }
     else
     {
         llDriveName.Text = discInDatabase.FromDrive;
     }
     if (discInDatabase.LogicalFolders != null)
     {
         ucItemFolderClassification.LogicalFolders = discInDatabase.LogicalFolders.ToArray();
     }
     // ucItemFolderClassification.ImageList = folderImages;
 }
Ejemplo n.º 4
0
        private static void WriteDisc(SQLiteConnection conn, DiscInDatabase disc)
        {
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = "insert into Discs (Format, Type, Free, Size, Label, " +
                                  "ScanTime, Serial, PhysicalLocation, FromDrive, Name, " +
                                  "Keywords, Flags, Desc, ClusterSize) values (";
                cmd.CommandText += "'" + disc.DriveFormat + "',";
                cmd.CommandText += "'" + (int)disc.DriveType + "',";
                cmd.CommandText += "'" + disc.TotalFreeSpace + "',";
                cmd.CommandText += "'" + disc.TotalSize + "',";
                cmd.CommandText += "'" + disc.VolumeLabel.Replace("'", "''") + "',";
                cmd.CommandText += "'" + disc.Scanned.ToUniversalTime() + "',";
                cmd.CommandText += "'" + disc.SerialNumber + "',";
                cmd.CommandText += "'" + disc.PhysicalLocation.Replace("'", "''") + "',";
                cmd.CommandText += "'" + disc.FromDrive + "',";
                cmd.CommandText += "'" + disc.Name + "',";
                cmd.CommandText += "'" + disc.Keywords.Replace("'", "''") + "',";
                cmd.CommandText += "'" + disc.Flags + "',";
                cmd.CommandText += "'" + disc.Description.Replace("'", "''") + "',";
                cmd.CommandText += "'" + disc.ClusterSize + "'";
                cmd.CommandText += ")";

                cmd.ExecuteNonQuery();

                // pass disc id for folders
                cmd.CommandText = "select last_insert_rowid()";
                Int64 lastRowId64 = (Int64)cmd.ExecuteScalar();
                int   lastRowId   = (int)lastRowId64;

                disc.DbId = lastRowId; // Needed for logical folder map

                WriteFiles(conn, -lastRowId, ((IFolder)disc).Files);
                WriteFolders(conn, -lastRowId, ((IFolder)disc).Folders);
            }
        }
Ejemplo n.º 5
0
 public void RemoveDisc(DiscInDatabase disc)
 {
     discs.Remove(disc);
 }
Ejemplo n.º 6
0
 public void AddDisc(DiscInDatabase disc)
 {
     discs.Add(disc);
 }
Ejemplo n.º 7
0
        internal static DiscInDatabase GetOptions(List <string> exludedElements, string drive, out LogicalFolder[] logicalFolders, Form parentForm, VolumeDatabase database, out DiscInDatabase discToReplace)
        {
            DlgReadVolume dlg       = new DlgReadVolume(drive);
            Cursor        oldCursor = parentForm.Cursor;

            parentForm.Cursor = Cursors.WaitCursor;
            try {
                discToReplace = null;
                dlg.database  = database;
                DriveInfo di = new DriveInfo(drive);
                dlg.tbUserLabel.Text = dlg.llCdLabel.Text = di.VolumeLabel;
                if (dlg.tbUserLabel.Text == string.Empty)
                {
                    dlg.tbUserLabel.Text = di.Name;
                }
                if (dlg.llCdLabel.Text == string.Empty)
                {
                    dlg.llCdLabel.Text = "(no label)";
                }
                dlg.llDriveFormat.Text             = di.DriveFormat;
                dlg.llDriveType.Text               = di.DriveType.ToString();
                dlg.llFreeSpace.Text               = di.TotalFreeSpace.ToKBAndB();
                dlg.llSize.Text                    = di.TotalSize.ToKBAndB();
                dlg.tbKeywords.Text                = string.Empty;
                dlg.tbPhysicalLocation.Text        = string.Empty;
                dlg.cbAutoEject.Checked            = Properties.Settings.Default.AutoEject;
                dlg.cbReadFileVersion.Checked      = Properties.Settings.Default.ReadFileInfo;
                dlg.llSerialNumber.Text            = Win32.GetVolumeSerialNumber(drive);
                dlg.cbComputeCrc.Checked           = Properties.Settings.Default.ComputeCrc;
                dlg.cbAutosaveAfterReading.Checked = Properties.Settings.Default.AutosaveAfterReading;
                dlg.cbBrowseZippedFiles.Checked    = Properties.Settings.Default.BrowseInsideCompressed;

                TreeNode node = new TreeNode();
                node.Tag                = di;
                node.Text               = di.Name.Replace(@"\", "");
                node.Checked            = true;
                node.SelectedImageIndex = node.ImageIndex = Win32.GetFileIconIndex(di.Name, Win32.FileIconSize.Small);
                Win32.UpdateSystemImageList(dlg.tvFileTree.ImageList, Win32.FileIconSize.Small, false, Properties.Resources.delete);
                dlg.tvFileTree.Nodes.Add(node);
                addLoadingString(node);
            }
            finally {
                parentForm.Cursor = oldCursor;
            }
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                DiscInDatabase discInDatabase = new DiscInDatabase();
                discInDatabase.Name             = dlg.tbUserLabel.Text;
                discInDatabase.Keywords         = dlg.tbKeywords.Text;
                discInDatabase.PhysicalLocation = dlg.tbPhysicalLocation.Text;
                logicalFolders = dlg.ucItemFolderClassification.LogicalFolders;
                Properties.Settings.Default.AutoEject              = dlg.cbAutoEject.Checked;
                Properties.Settings.Default.ReadFileInfo           = dlg.cbReadFileVersion.Checked;
                Properties.Settings.Default.ComputeCrc             = dlg.cbComputeCrc.Checked;
                Properties.Settings.Default.AutosaveAfterReading   = dlg.cbAutosaveAfterReading.Checked;
                Properties.Settings.Default.BrowseInsideCompressed = dlg.cbBrowseZippedFiles.Checked;
                if (dlg.cbReadFromSelected.Checked)
                {
                    getExcludedElements(exludedElements, dlg.tvFileTree.Nodes);
                }
                discToReplace = dlg.returnDiscToReplace();
                return(discInDatabase);
            }
            else
            {
                logicalFolders = null;
                return(null);
            }
        }