示例#1
0
        private void button11_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count == -1)
            {
                return;
            }

            foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
            {
                string path = item.Cells["FilePath"].Value.ToString();

                //删除文件
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    CodeAll.AddLog("文件删除失败", path, ex.Message);
                    continue;
                }

                this.dataGridView1.Rows.Remove(item);
            }
        }
示例#2
0
        //检查是否存在
        public static bool ExistData(string FilePath, string DataType, string MD5)
        {
            FileInfo fi = new FileInfo(FilePath);

            long     FileSize  = fi.Length;
            DateTime CreatTime = fi.CreationTime;

            if (MD5 == "")
            {
                MD5 = CodeAll.GetMD5(FilePath);
            }



            OleDbCommand command = new OleDbCommand();

            command.Connection = conn;
            OleDbDataReader dr = null;

            command.CommandText = "select [MD5] from " + DataType + " where [MD5] = '" + MD5 + "'";

            try
            {
                dr = command.ExecuteReader();
                bool Exist = dr.HasRows;
                return(Exist);
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("查询数据库失败", FilePath, ex.Message);

                return(true);
            }
        }
示例#3
0
        //查询数据库所有类型(是否存在文件)
        //1.路径,名称,类型
        //2.反回查询结果
        public static AccessType CheckData(string FilePath, string DataType, string MD5)
        {
            if (MD5 == "")
            {
                MD5 = CodeAll.GetMD5(FilePath);
            }

            DataTable dt = GetAccess("select * from " + DataType + " where MD5='" + MD5 + "'");

            if (dt == null)
            {
                return(null);
            }

            AccessType AT = new AccessType();

            if (dt.Rows.Count != 0)
            {
                AT.Name       = dt.Rows[0][1].ToString();
                AT.Size       = dt.Rows[0][2].ToString();
                AT.MD5        = dt.Rows[0][3].ToString();
                AT.UpdateTime = dt.Rows[0][4].ToString();
                AT.CreatTime  = dt.Rows[0][5].ToString();
                AT.isDel      = dt.Rows[0][6].ToString();
            }
            else
            {
                return(null);
            }

            return(AT);
        }
示例#4
0
        private void listBoxFile_DragDrop(object sender, DragEventArgs e)
        {
            string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            foreach (string o in s)
            {
                //搜索拖入的路径,是目录,扫描视频文件

                if (System.IO.File.Exists(o))
                {
                    if (CodeAll.isVideo(o))
                    {
                        this.listBoxFile.Items.Add(o);
                    }
                }
                else if (System.IO.Directory.Exists(o))
                {
                    List <string> lst = CodeAll.ScanVideo(o, "*", SearchOption.AllDirectories);

                    foreach (var item in lst)
                    {
                        this.listBoxFile.Items.Add(item);
                    }
                }
            }
        }
示例#5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //只判断处理文件夹
            foreach (string path in this.listBoxNameSet.Items)
            {
                if (Directory.Exists(path))
                {
                    string NewName = path.Substring(path.LastIndexOf("\\") + 1);
                    string NewPath = path.Remove(path.LastIndexOf("\\"));

                    List <string> file = CodeAll.ScanVideo(path, "*", SearchOption.AllDirectories);
                    if (file.Count != 1)
                    {
                        continue;
                    }

                    if (File.Exists(NewPath + "\\" + NewName + Path.GetExtension(file[0])))
                    {
                        continue;
                    }

                    try
                    {
                        File.Move(file[0], NewPath + "\\" + NewName + Path.GetExtension(file[0]));
                        Directory.Delete(path, true);
                    }
                    catch (Exception ex)
                    {
                        CodeAll.AddLog("移动失败", path, ex.Message);
                    }
                }
            }
        }
示例#6
0
        public static void CreatTxtFile(string FilePath, string Name)
        {
            string DelPath = setting.DelTxtPath;

            if (Directory.Exists(DelPath) == false)
            {
                CodeAll.AddLog("文本数据库路径不存在", "", "");
                DelPath = setting.TempDelTxtPath;
                if (Directory.Exists(DelPath) == false)
                {
                    Directory.CreateDirectory(DelPath);
                }
            }

            if (File.Exists(FilePath) == false)
            {
                CodeAll.AddLog("NoFilePath", FilePath, "");
                return;
            }

            //获取文件大小


            long   lSize = new FileInfo(FilePath).Length;
            string size  = "";

            if (lSize >= 1073741824)
            {
                size = (lSize / 1024.00 / 1024.00 / 1024.00).ToString("F2") + "G";
            }
            else if (lSize >= 1048576)
            {
                size = (lSize / 1024.00 / 1024.00).ToString("F2") + "MB";
            }
            else if (lSize >= 1024)
            {
                size = (lSize / 1024.00).ToString("F2") + "KB";
            }
            else
            {
                size = lSize.ToString("F2") + "B";
            }

            //////////////////////////////////////////////

            string TxtPath = DelPath + Name + " " + size + ".txt";

            if (File.Exists(TxtPath) == false)
            {
                FileStream myFs = new FileStream(TxtPath, FileMode.Create);
                myFs.Close();
            }
            else
            {
                CodeAll.AddLog("Txt数据已存在", TxtPath, "");
            }
        }
示例#7
0
        //添加数据库
        //1.路径,名称,类型,是否删除
        //2.校验MD5数值,查询数据库是否存在
        //3.存在没标记删除(标记删除并记录),存在已标记删除(报错),不存在(添加)

        public static bool AddData(string FilePath, string Name, string DataType, string MD5, bool isDel)
        {
            if (DataType == "")
            {
                CodeAll.AddLog("数据库添加失败", "", "为选择类型");

                return(false);
            }

            //获取文件信息

            FileInfo fi = new FileInfo(FilePath);

            long     FileSize  = fi.Length;
            DateTime CreatTime = fi.CreationTime;

            if (MD5 == "")
            {
                MD5 = CodeAll.GetMD5(FilePath);
            }


            if (MD5 == "")
            {
                return(false);
            }

            //先查询是否存在 存在跳过 不存在添加数据

            if (ExistData(FilePath, DataType, MD5) == true)
            {
                CodeAll.AddLog("数据库添加失败", FilePath, "已存在");

                if (isDel)
                {
                    UpdateAccess("update " + DataType + " set [isDel] = " + isDel + " where [MD5] = '" + MD5 + "'");
                    CodeAll.AddLog("数据库标记删除", "", isDel.ToString());
                }
                else
                {
                    CodeAll.AddLog("跳过", "", "");
                }

                return(false);
            }
            else
            {
                return(UpdateAccess("insert into " + DataType + "([Name],[Size],[MD5],[UpdateTime],[CreatTime],[isDel]) values ('" + Name.Replace("'", "") + "','" + FileSize + "','" + MD5 + "','" + DateTime.Now + "','" + CreatTime + "'," + isDel + ")"));
            }
        }
示例#8
0
        private void button22_Click(object sender, EventArgs e)
        {
            //只处理文件夹
            string WorkPath = setting.ConcatVideoPath;

            System.IO.Directory.CreateDirectory(WorkPath);
            string txtLst = "";
            string txtSh  = "";

            int index = 0;

            foreach (string folder in listBoxNameSet.Items)
            {
                if (!Directory.Exists(folder))
                {
                    continue;
                }

                List <string> files = CodeAll.ScanVideo(folder, "*", SearchOption.TopDirectoryOnly);

                if (files.Count < 2)
                {
                    continue;
                }
                files.Sort();

                string txtConcat = "";

                txtLst += folder + "\r\n";
                foreach (string file in files)
                {
                    txtLst    += "\t\t" + System.IO.Path.GetFileName(file) + "\r\n";
                    txtConcat += "file '" + ConcatTransFolder(file) + "'\n";
                }

                DLL.TxtStr.Write(txtConcat, WorkPath + index.ToString() + ".txt", true, new System.Text.UTF8Encoding(false));

                txtSh += "ffmpeg -f concat -safe 0 -i " + index.ToString() + ".txt" + " -c copy " + " '" + ConcatTransFolder(folder) + "/all" + System.IO.Path.GetExtension(files[0]) + "'\n";

                txtSh += "chmod 777 '" + ConcatTransFolder(folder) + "/all" + System.IO.Path.GetExtension(files[0]) + "'\n";

                index++;
            }

            DLL.TxtStr.Write(txtSh, WorkPath + "x.sh", true, new System.Text.UTF8Encoding(false));
            DLL.TxtStr.Write(txtLst, WorkPath + "lst.txt", true);
        }
示例#9
0
        public static DataTable GetAccess(string sql)
        {
            OleDbCommand command = new OleDbCommand();

            command.Connection = conn;

            OleDbDataReader dr = null;

            command.CommandText = sql;
            DataTable dt = new DataTable();


            try
            {
                dr = command.ExecuteReader();

                for (int i = 0; i < dr.FieldCount; i++)
                {
                    DataColumn dc = new DataColumn(dr.GetName(i), dr.GetFieldType(i));
                    dt.Columns.Add(dc);
                }

                while (dr.Read())
                {
                    DataRow ddr = dt.NewRow();
                    for (int i = 0; i < dr.FieldCount; i++)
                    {
                        ddr[i] = dr.GetValue(i).ToString();
                    }
                    dt.Rows.Add(ddr);
                }


                dr.Dispose();

                return(dt);
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("数据库操作失败", sql, ex.Message);
                return(null);
            }
        }
示例#10
0
        private void button14_Click(object sender, EventArgs e)
        {
            //是文件添加后缀修改,是文件夹直接修改

            List <string> Namelst = System.Text.RegularExpressions.Regex.Split(this.richTextBox2.Text.Trim(), "\n").ToList <string>();

            if (Namelst.Count != listBoxNameSet.Items.Count)
            {
                MessageBox.Show("文件数不一致");
                return;
            }

            for (int i = 0; i < listBoxNameSet.Items.Count; i++)
            {
                string OriPath = listBoxNameSet.Items[i].ToString();

                if (File.Exists(OriPath))
                {
                    string newPath = Path.GetDirectoryName(OriPath) + "\\" + Namelst[i].Trim() + Path.GetExtension(OriPath);
                    if (File.Exists(newPath))
                    {
                        continue;
                    }
                    File.Move(OriPath, newPath);
                }
                else if (Directory.Exists(OriPath))
                {
                    string newPath = Path.GetDirectoryName(OriPath) + "\\" + Namelst[i].Trim();
                    if (Directory.Exists(newPath))
                    {
                        continue;
                    }
                    Directory.Move(OriPath, newPath);
                }
                else
                {
                    CodeAll.AddLog("文件改名失败", OriPath, "文件不存在");
                }
            }

            MessageBox.Show("Done");
        }
示例#11
0
        private void Form_DragDrop(object sender, DragEventArgs e)
        {
            string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            foreach (string o in s)
            {
                //搜索拖入的路径,是目录,扫描视频文件
                string Str = "";
                if (CodeAll.isVideo(o))
                {
                    if (radioButton1.Checked)
                    {
                        Str = getSerialName(o);
                    }
                }

                if (Str != "")
                {
                    DLL.SystemCMD.RunCmd("cmd.exe", setting.EverythingPath + " -s \"" + Str + "\"");
                }
            }
        }
示例#12
0
        public static bool UpdateAccess(string sql)
        {
            OleDbCommand command = new OleDbCommand();

            command.Connection = conn;

            command.CommandText = sql;

            try
            {
                command.ExecuteNonQuery();

                return(true);
            }

            catch (Exception ex)
            {
                CodeAll.AddLog("数据库操作失败", sql, ex.Message);

                return(false);
            }
        }
示例#13
0
        private void buttonDelSame_Click(object sender, EventArgs e)
        {
            //删除文件
            if (this.listBoxMD5.SelectedIndex == -1 || this.listBoxFile.SelectedIndex == -1)
            {
                return;
            }



            string path = this.listBoxFile.Items[this.listBoxFile.SelectedIndex].ToString();

            path = CodeClass.SameStrClear(path);


            if (System.IO.File.Exists(path) == false)
            {
                CodeAll.AddLog("文件删除失败", path, "文件不存在");
                return;
            }

            //删除文件
            try
            {
                File.Delete(path);
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("文件删除失败", path, ex.Message);
                return;
            }

            int selectIndex = this.listBoxFile.SelectedIndex;

            this.listBoxMD5.Items.RemoveAt(selectIndex);
            this.listBoxFile.Items.RemoveAt(selectIndex);

            CheckSameMD5List();
        }
示例#14
0
        private void listBoxNameSet_DragDrop(object sender, DragEventArgs e)
        {
            string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            foreach (string o in s)
            {
                //如果是文件,只导入视频,如果是文件夹,直接导入

                if (System.IO.File.Exists(o))
                {
                    if (checkBox1.Checked)
                    {
                        this.listBoxNameSet.Items.Add(o);
                    }
                    else if (CodeAll.isVideo(o))
                    {
                        this.listBoxNameSet.Items.Add(o);
                    }
                }
                else if (System.IO.Directory.Exists(o))
                {
                    this.listBoxNameSet.Items.Add(o);
                }
            }
        }
示例#15
0
        //获取文件MD5校验码
        public static string GetMD5(string strFile)
        {
            try
            {
                int iFileSize = 30 * 1024 * 1024;

                //以文件的全路径对应的字符串和文件打开模式来初始化FileStream文件流实例
                FileStream SplitFileStream = new FileStream(strFile, FileMode.Open);
                //以FileStream文件流来初始化BinaryReader文件阅读器
                BinaryReader SplitFileReader = new BinaryReader(SplitFileStream);
                //每次分割读取的最大数据
                byte[] TempBytes = SplitFileReader.ReadBytes(iFileSize);

                MD5 md5 = MD5.Create();

                byte[] data2 = md5.ComputeHash(TempBytes);



                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < data2.Length; i++)
                {
                    sb.Append(data2[i].ToString("x2"));
                }

                SplitFileStream.Close();
                SplitFileReader.Close();
                return(sb.ToString());
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("MD5验证失败", strFile, ex.Message);

                return("");
            }
        }
示例#16
0
        //检查文件是否存在数据库
        private void button10_Click(object sender, EventArgs e)
        {
            access.Open();
            int n = 0;

            this.listBoxMD5.Items.Clear();



            for (int i = 0; i < this.listBoxFile.Items.Count; i++)
            {
                string path = this.listBoxFile.Items[i].ToString();

                //校验MD5数值
                string MD5 = CodeAll.GetMD5(path);

                //检查数据库是否存在
                string            DataType = "G";
                access.AccessType AT       = access.CheckData(path, DataType, MD5);



                if (AT == null)
                {
                    DataType = "F";
                    AT       = access.CheckData(path, DataType, MD5);
                }

                if (AT == null)
                {
                    DataType = "J";
                    AT       = access.CheckData(path, DataType, MD5);
                }

                if (AT == null)
                {
                    DataType = "TV";
                    AT       = access.CheckData(path, DataType, MD5);
                }



                if (AT == null)//不存在,添加listboxMD5值
                {
                    this.listBoxMD5.Items.Add(MD5);
                    n++;
                }
                else//存在,从listboxfile中移除,并添加Datatable
                {
                    this.listBoxFile.Items.RemoveAt(i);
                    i--;

                    FileInfo fi   = new FileInfo(path);
                    string   Size = fi.Length.ToString();

                    string NewName = "";
                    if (AT.Name != System.IO.Path.GetFileNameWithoutExtension(path))
                    {
                        NewName = System.IO.Path.GetFileNameWithoutExtension(path);
                    }

                    this.dataGridView1.Rows.Add(
                        AT.isDel,
                        AT.Name,
                        NewName,
                        DataType,
                        GetDataType(),
                        AT.Size,
                        Size,
                        MD5,
                        path
                        );
                }



                this.label2.Text = n.ToString() + "/" + this.listBoxFile.Items.Count.ToString();
                Application.DoEvents();
            }

            //检查MD5数量和文件数量
            if (this.listBoxMD5.Items.Count != this.listBoxFile.Items.Count)
            {
                MessageBox.Show("MD5数据数量和文件不一致");
            }

            //检查MD5是否有重复
            List <string> lst = new List <string>();

            CheckSameMD5List();

            access.Close();
        }
示例#17
0
        private void button4_Click(object sender, EventArgs e)
        {
            access.Open();
            if (MessageBox.Show("是否确认删除", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
            {
                return;
            }



            for (int i = 0; i < this.listBoxFile.Items.Count; i++)
            {
                string path = this.listBoxFile.Items[i].ToString();
                string Name = Path.GetFileNameWithoutExtension(path);


                if (GetDataType() == "")
                {
                    MessageBox.Show("未选择类型");

                    return;
                }

                string DataType = GetDataType();

                //除了G创建文本数据库
                if (DataType != "G")
                {
                    CodeClass.CreatTxtFile(path, Name);
                }


                //除了TXT模式创建MDB数据库
                if (DataType != "TXT")
                {
                    //listboxMD5数据数量不一致就重新计算MD5

                    string MD5 = "";


                    if (this.listBoxMD5.Items.Count == this.listBoxFile.Items.Count)
                    {
                        MD5 = this.listBoxMD5.Items[i].ToString();
                    }

                    if (access.AddData(path, Name, DataType, "", true) == false)
                    {
                        continue;
                    }
                }


                //删除文件
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    CodeAll.AddLog("文件删除失败", path, ex.Message);
                    continue;
                }
            }


            Clear();

            access.Close();
        }