Esempio n. 1
0
        private void CaptureFileInfo(TreeNode nodeTop)
        {
            /*
             * J vincent
             * goes through files in tree below catalogue root and captures data from files not already in catalogue
             * tests first to see if already in catalogue
             * and that not a system file or directory
             *
             */

            ReadFileInfo fileInfo = new ReadFileInfo();


            foreach (TreeNode nodeSub in nodeTop.Nodes)
            {
                fileInfo.GetFileInfo(nodeSub.FullPath);
                //need to pass full path including actual location so add globals.curcatpath
                int alreadyHere = CheckSum.CheckCheckSum(Globals.curCatPath + fileInfo.fileLocation, fileInfo.fileName);
                if ((fileInfo.fileSystem == false && fileInfo.fileDir == false && alreadyHere == 0))
                {
                    if (fileInfo.fileName != null)
                    {
                        CatalogueItemMetaUpdate intoCat = new CatalogueItemMetaUpdate();
                        //add file information to tbl Items
                        intoCat.AddItem(fileInfo.fileName, fileInfo.fileLocation, fileInfo.fileHash, fileInfo.fileOwner);
                        //get ItemID
                        int myItemID = intoCat.itemID;
                        //add meta data to tblMetaItems for each metaTitle if available
                        if (fileInfo.fileMetaType != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "TYPE OF FILE", "string", fileInfo.fileMetaType);
                        }
                        if (fileInfo.fileName != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "NAME", "string", fileInfo.fileName);
                        }
                        if (fileInfo.fileMetaSize != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "SIZE", "INT", fileInfo.fileMetaSize);
                        }
                        if (fileInfo.fileMetaDateCreated != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "CREATED", "DateTime", fileInfo.fileMetaDateCreated);
                        }
                        if (fileInfo.fileMetaDateModified != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "MODIFIED", "DateTime", fileInfo.fileMetaDateModified);
                        }
                        if (fileInfo.fileMetaReadOnly != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "READ ONLY", "Boolean", fileInfo.fileMetaReadOnly);
                        }
                        if (fileInfo.fileLocation != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "LOCATION", "string", fileInfo.fileLocation);
                        }
                        if (fileInfo.fileMetaHidden != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "HIDDEN", "Boolean", fileInfo.fileMetaHidden);
                        }
                        if (fileInfo.fileMetaDateTaken != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "DATE TAKEN", "DateTime", fileInfo.fileMetaDateTaken);
                        }
                        if (fileInfo.fileMetaKeyword != null)
                        {
                            intoCat.AddMetaItem(myItemID, true, "KEYWORDS", "string", fileInfo.fileMetaKeyword);
                        }
                        //update catalogue latest version
                        intoCat.SetCatalogueVer();
                        toolStripVersion.Text = "Cat ver: " + Globals.curCatVer;
                        //update change log
                        ChangeLog.Main("New File Added: " + fileInfo.fileName, myItemID);
                        filesUpdated++;
                    }
                }
                //recursively call this method again until entire tree covered
                CaptureFileInfo(nodeSub);
            }

            //or selected files in current structure
            //later
        }
Esempio n. 2
0
        private void treeViewCat_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            /*
             * J Vincent
             * name autogenerated by visual studio
             * This populates the tree view with the files in the folder
             *
             * it needs to be compared with the details of files stored in the catalogue
             * and highlight any discrepenacies
             * and hide the DACAT folder
             *
             */

            if (e.Node.Nodes.Count > 0)
            {
                if (e.Node.Nodes[0].Text == "..." && e.Node.Nodes[0].Tag == null)
                {
                    e.Node.Nodes.Clear();

                    //get the list of sub direcotires
                    string[] dirs = Directory.GetDirectories(e.Node.Tag.ToString());

                    foreach (string dir in dirs)
                    {
                        DirectoryInfo di   = new DirectoryInfo(dir);
                        TreeNode      node = new TreeNode(di.Name, 1, 2);
                        //if its the DACAT folder ignore
                        if (di.Name != "DACAT")
                        {
                            try
                            {
                                //keep the directory's full path in the tag for use later
                                node.Tag = dir;

                                //if the directory has sub directories add the place holder
                                if (di.GetDirectories().Count() > 0)
                                {
                                    node.Nodes.Add(null, "...", 0, 0);
                                }

                                foreach (var file in di.GetFiles())
                                {
                                    //check if file is already in db
                                    string   fileDets = file.DirectoryName;
                                    int      checkRes = CheckSum.CheckCheckSum(fileDets, file.Name);
                                    TreeNode n;
                                    switch (checkRes)
                                    {
                                    case 0:     //not in db
                                        n = new TreeNode(file.Name, 4, 4);
                                        break;

                                    case 1:     //in db, checksum wrong
                                        n = new TreeNode(file.Name, 5, 5);
                                        break;

                                    case 2:     //in db, all ok
                                        n = new TreeNode(file.Name, 6, 6);
                                        break;

                                    default:
                                        n = new TreeNode(file.Name, 4, 4);
                                        break;
                                    }
                                    n.Tag = CheckSum.itemID;
                                    node.Nodes.Add(n);
                                }
                            }
                            catch (UnauthorizedAccessException)
                            {
                                //display a locked folder icon
                                node.ImageIndex         = 3;
                                node.SelectedImageIndex = 3;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "DirectoryLister",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            finally
                            {
                                e.Node.Nodes.Add(node);
                            }
                        }
                    }
                    //add files of rootdirectory
                    DirectoryInfo rootDir = new DirectoryInfo(e.Node.Tag.ToString());
                    foreach (var file in rootDir.GetFiles())
                    {
                        //check if file is already in db
                        string   fileDets = file.DirectoryName;
                        int      checkRes = CheckSum.CheckCheckSum(fileDets, file.Name);
                        TreeNode n;
                        switch (checkRes)
                        {
                        case 0:     //not in db
                            n = new TreeNode(file.Name, 4, 4);
                            break;

                        case 1:     //in db, checksum wrong
                            n = new TreeNode(file.Name, 5, 5);
                            break;

                        case 2:     //in db, all ok
                            n = new TreeNode(file.Name, 6, 6);
                            break;

                        default:
                            n = new TreeNode(file.Name, 4, 4);
                            break;
                        }
                        n.Tag = CheckSum.itemID;
                        e.Node.Nodes.Add(n);
                    }

                    //add missing files to treeview - these are files in the database that aren't in the folder
                    List <int> missing = Catalogue.MissingItems();
                    foreach (int missingFile in missing)
                    {
                        string[] filenames = Catalogue.GetFileName(missingFile);
                        TreeNode n;
                        n     = new TreeNode(filenames[0], 7, 7);
                        n.Tag = missingFile;
                        e.Node.Nodes.Add(n);
                        //update change logs
                        ChangeLog.Main("Missing File: " + Globals.curCatPath + filenames[1] + "\\" + filenames[0], missingFile);
                    }
                    treeViewCat.ExpandAll();
                }
            }
        }