Beispiel #1
0
        private void UpdateLableTreeView()
        {
            PDFFileModel model = Global.Model;

            List <TreeNode> treeNodes = new List <TreeNode>();

            treeViewLable.BeginUpdate();
            treeViewLable.Nodes.Clear();

            int i = 0;

            foreach (Lable l in model.Lables)
            {
                TreeNode node = new TreeNode(l.name);
                node.Tag = i++;
                treeNodes.Add(node);
            }

            for (i = 0; i < model.Lables.Count; i++)
            {
                Lable l = model.Lables[i];
                if (l.parent == -1)
                {
                    treeViewLable.Nodes.Add(treeNodes[i]);
                }
                else
                {
                    treeNodes[l.parent].Nodes.Add(treeNodes[i]);
                }
            }

            treeViewLable.EndUpdate();
            treeViewLable.ExpandAll();
        }
        private void CalcFileMD5(PDFFileModel model, ShowParseFileInfo ShowInfo)
        {
            int count = 0;

            for (int i = 0; i < model.Files.Count; i++)
            {
                if (model.Files[i].md5 == null || model.Files[i].md5 == string.Empty)
                {
                    count++;
                }
            }

            int index = 0;
            MD5 md5   = MD5.Create();

            for (int i = 0; i < model.Files.Count; i++)
            {
                if (model.Files[i].md5 != null && model.Files[i].md5 != string.Empty)
                {
                    continue;
                }

                if (ShowInfo != null)
                {
                    string info = string.Format("共{0}个文件,正在计算第{1}个文件", count, index++);
                    ShowInfo(info);
                }

                GetFileMeta(model.Files[i], md5);
            }
        }
Beispiel #3
0
        private void UpdateTreeView()
        {
            PDFFileModel model = Global.Model;

            List <TreeNode> treeNodes = new List <TreeNode>();

            treeViewDir.BeginUpdate();
            treeViewDir.Nodes.Clear();

            int i = 0;

            foreach (FileDirectory dir in model.Directories)
            {
                TreeNode node = new TreeNode(dir.name);
                node.Tag = i++;
                treeNodes.Add(node);
            }

            for (i = 0; i < model.Directories.Count; i++)
            {
                FileDirectory d = model.Directories[i];
                if (d.parent == -1)
                {
                    treeViewDir.Nodes.Add(treeNodes[i]);
                }
                else
                {
                    treeNodes[d.parent].Nodes.Add(treeNodes[i]);
                }
            }

            treeViewDir.EndUpdate();
        }
Beispiel #4
0
        public static PDFFileModel LoadFromFile(string pathName)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            Stream          destream  = new FileStream(pathName, FileMode.Open, FileAccess.Read, FileShare.Read);
            PDFFileModel    o         = (PDFFileModel)formatter.Deserialize(destream);

            destream.Flush();
            destream.Close();
            return(o);
        }
        public PDFFileModel BuildNewData(string path, ShowParseFileInfo ShowInfo)
        {
            if (!Directory.Exists(path))
            {
                return(null);
            }

            PDFFileModel model = ListFiles(path);

            CalcFileMD5(model, ShowInfo);

            return(model);
        }
Beispiel #6
0
        private void LoadProject(string pathName)
        {
            if (!File.Exists(pathName))
            {
                MessageBox.Show("文件不存在: " + pathName);
                return;
            }

            Global.Model = PDFFileModel.LoadFromFile(pathName);
            Global.Config.LastProject = Path.GetFileNameWithoutExtension(pathName);

            this.Text = "FileTagger - " + Global.Config.LastProject;

            UpdateTreeView();
            UpdateLableTreeView();
        }
        public void MergeDirctory(string from, string to, string MidDir, ShowParseFileInfo ShowInfo)
        {
            PDFFileModel model = null;

            if (to != null)
            {
                model = ListFiles(to);
                CalcFileMD5(model, ShowInfo);
            }
            else
            {
                model = Global.Model;
            }
            HashSet <string> set = new HashSet <string>();

            for (int i = 0; i < model.Files.Count; i++)
            {
                set.Add(model.Files[i].md5);
            }

            model = ListFiles(from);
            CalcFileMD5(model, ShowInfo);
            List <int> toMerge = new List <int>();

            for (int i = 0; i < model.Files.Count; i++)
            {
                if (!set.Contains(model.Files[i].md5))
                {
                    toMerge.Add(i);
                }
            }

            for (int i = 0; i < toMerge.Count; i++)
            {
                if (MidDir[MidDir.Length - 1] != '\\' && MidDir[MidDir.Length - 1] != '/')
                {
                    MidDir += '/';
                }
                string origFile     = model.Files[toMerge[i]].filePath;
                string fileDestPath = MidDir + Path.GetFileName(origFile);
                File.Copy(origFile, fileDestPath);
                File.Copy(origFile + ".met", fileDestPath + ".met");
            }
        }
        private void ListFiles_r(PDFFileModel model, string pathName, int dirIndex)
        {
            if (Directory.Exists(pathName))
            {
                FileDirectory newDir = new FileDirectory();
                newDir.pathName = pathName;
                newDir.name     = Path.GetFileName(pathName);

                newDir.parent = dirIndex;
                int index = model.Directories.Count;
                model.Directories.Add(newDir);

                //文件夹及子文件夹下的所有文件的全路径
                IEnumerable <string> files = Directory.EnumerateFileSystemEntries(pathName, "*.*", SearchOption.TopDirectoryOnly);
                foreach (string p in files)
                {
                    ListFiles_r(model, p, index);
                }
            }
            else if (File.Exists(pathName))
            {
                if (Path.GetExtension(pathName) == ".met")
                {
                    string name = pathName.Substring(0, pathName.Length - 4);
                    if (!File.Exists(name))
                    {
                        metaOnlyFile_.Add(pathName);
                    }
                    return;
                }
                FileData fileData = new FileData();
                fileData.filePath = pathName;
                fileData.name     = Path.GetFileName(pathName);

                int index = model.Files.Count;
                model.Files.Add(fileData);
                model.Directories[dirIndex].files.Add(index);
            }
        }
        private PDFFileModel ListFiles(string path)
        {
            metaOnlyFile_ = new List <string>();
            PDFFileModel model = new PDFFileModel();

            model.Path = path;

            FileDirectory dir = new FileDirectory();

            dir.pathName = path;
            dir.name     = Path.GetFileName(path);
            dir.parent   = -1;
            model.Directories.Add(dir);

            //文件夹及子文件夹下的所有文件的全路径
            IEnumerable <string> files = Directory.EnumerateFileSystemEntries(path, "*.*", SearchOption.TopDirectoryOnly);

            foreach (string pathName in files)
            {
                ListFiles_r(model, pathName, 0);
            }

            return(model);
        }
Beispiel #10
0
        private void toolStripOpenFolder_Click(object sender, EventArgs e)
        {
            FormNewProject form = new FormNewProject();

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                Global.Config.LastProject = form.ProjectName;
                if (File.Exists(Global.Config.ProjectFullFileName))
                {
                    MessageBox.Show("已有相同项目名,保存时会覆盖!");
                }
            }
            else
            {
                return;
            }

            FolderBrowserDialog dlg = new FolderBrowserDialog();

            dlg.SelectedPath = Global.Config.SelectPath;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Console.WriteLine(dlg.SelectedPath);
            Global.Config.SelectPath = dlg.SelectedPath;
            PDFFileModel model = Global.Controller.BuildNewData(dlg.SelectedPath, StatusBarShowInfo);

            if (model == null)
            {
                return;
            }

            Global.Model = model;

            this.Text = "FileTagger - " + Global.Config.LastProject;

            UpdateTreeView();
            UpdateLableTreeView();

            if (Global.Controller.MetaOnlyFile.Count > 0)
            {
                foreach (string f in Global.Controller.MetaOnlyFile)
                {
                    listViewFile.Items.Add(f);
                }

                DialogResult result = MessageBox.Show("删除多余的meta文件?", "", MessageBoxButtons.OKCancel);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (string f in Global.Controller.MetaOnlyFile)
                    {
                        File.Delete(f);
                    }
                    listViewFile.Clear();
                }
            }


            StatusBarShowInfo("ok!");
        }
Beispiel #11
0
 public static void Init()
 {
     m_Controller = new PDFManagerController();
     Model        = new PDFFileModel();
     m_Config     = Config.Load();
 }
        // 更新数据
        // 文件的增加和删除
        public void UpdateData(ShowParseFileInfo ShowInfo)
        {
            LogInfo(ShowInfo, "list all files...");
            PDFFileModel newModel = ListFiles(Global.Model.Path);

            LogInfo(ShowInfo, "comparing...");
            Dictionary <string, UpdateFileInfo> oldFiles = new Dictionary <string, UpdateFileInfo>();

            for (int i = 0; i < Global.Model.Files.Count; i++)
            {
                FileData f = Global.Model.Files[i];

                UpdateFileInfo info = new UpdateFileInfo();
                info.fileIndex = i;
                info.matched   = false;
                oldFiles.Add(f.filePath, info);
            }

            // find deleted files and new files
            List <int>            newFileIndex  = new List <int>();
            Dictionary <int, int> oldToNewIndex = new Dictionary <int, int>();

            for (int i = 0; i < newModel.Files.Count; i++)
            {
                FileData       f = newModel.Files[i];
                UpdateFileInfo info;
                if (oldFiles.TryGetValue(f.filePath, out info))
                {
                    info.matched = true;
                    oldToNewIndex.Add(info.fileIndex, i);
                    f.md5  = Global.Model.Files[info.fileIndex].md5;
                    f.size = Global.Model.Files[info.fileIndex].size;
                }
                else
                {
                    newFileIndex.Add(i);
                }
            }

            LogInfo(ShowInfo, "delete files...");
            foreach (KeyValuePair <string, UpdateFileInfo> p in oldFiles)
            {
                if (!p.Value.matched)
                {
                    DeleteFile(p.Value.fileIndex);
                }
            }

            LogInfo(ShowInfo, "add new files...");
            CalcFileMD5(newModel, ShowInfo);

            LogInfo(ShowInfo, "remap lable...");
            RemapFiles(oldToNewIndex);

            LogInfo(ShowInfo, "ok!");

            newModel.Lables = Global.Model.Lables;
            Global.Model    = newModel;

            string time = DateTime.Today.ToShortDateString() + " ";

            time += DateTime.Now.ToShortTimeString();
            time  = time.Replace('/', '_').Replace(':', '_');
            string       logFileName = Config.ProjectPath + "\\" + time + ".log";
            FileStream   fs          = new FileStream(logFileName, FileMode.Create, FileAccess.Write);
            StreamWriter sw          = new StreamWriter(fs);
            int          count       = 0;

            sw.WriteLine("delete files");
            foreach (KeyValuePair <string, UpdateFileInfo> p in oldFiles)
            {
                if (!p.Value.matched)
                {
                    sw.WriteLine(p.Key);
                    count++;
                }
            }
            sw.WriteLine("{0} files deleted", count);

            sw.WriteLine();
            sw.WriteLine("added files");
            for (int i = 0; i < newFileIndex.Count; i++)
            {
                FileData f = newModel.Files[newFileIndex[i]];
                sw.WriteLine(f.filePath);
            }
            sw.WriteLine("{0} files added", newFileIndex.Count);

            sw.Close();
            fs.Close();
        }