コード例 #1
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            string strCheckDir = this.txtDir.Text.Trim();

            if (!Directory.Exists(strCheckDir))
            {
                MessageBox.Show("Check Dir not exist:" + strCheckDir);
                return;
            }

            List <EntPicM>   lstPicM   = new List <EntPicM>();
            List <EntVedioM> lstVedioM = new List <EntVedioM>();

            List <string> lstFiles = new List <string>();

            lstFiles.AddRange(Directory.GetFiles(strCheckDir, "*.*", SearchOption.AllDirectories));
            //for temp debug
            //lstFiles.AddRange(Directory.GetFiles(Path.Combine(strCheckDir, "mi"), "*.*", SearchOption.AllDirectories));
            //lstFiles.AddRange(Directory.GetFiles(Path.Combine(strCheckDir, "mi note"), "*.*", SearchOption.AllDirectories));
            //lstFiles.AddRange(Directory.GetFiles(Path.Combine(strCheckDir, "嫲嫲"), "*.*", SearchOption.AllDirectories));

            //string[] strFiles = Directory.GetFiles(strCheckDir, "*.*", SearchOption.AllDirectories);
            int cntPic   = 0;
            int cntVedio = 0;

            foreach (string itemFile in lstFiles)
            {
                if (itemFile.ToUpper().Contains(".JPG") || itemFile.ToUpper().Contains(".PNG"))
                {
                    EntPicM entPM = this.Init_fr_file(itemFile);
                    lstPicM.Add(entPM);

                    if (lstPicM.Count > 100)
                    {
                        cntPic += lstPicM.Count;
                        this.DoSavePic(lstPicM, true);
                        System.Diagnostics.Debug.WriteLine(string.Format("process picture:{0}", cntPic));
                        lstPicM.Clear();
                    }
                }
                else if (itemFile.ToUpper().Contains(".MP4") || itemFile.ToUpper().Contains(".MOV"))
                {
                    EntVedioM entVM = Vedio_Init_fr_File(itemFile);
                    lstVedioM.Add(entVM);

                    if (lstVedioM.Count > 100)
                    {
                        cntVedio += lstVedioM.Count;
                        this.DoSaveVideo(lstVedioM, true);
                        System.Diagnostics.Debug.WriteLine(string.Format("process vedio:{0}", cntVedio));
                        lstVedioM.Clear();
                    }
                }
            }

            this.DoSavePic(lstPicM, true);
            this.DoSaveVideo(lstVedioM, true);
            MessageBox.Show("OK");
        }
コード例 #2
0
        private void btnTempAction_Click(object sender, EventArgs e)
        {
            string strCheckDir = this.txtDir.Text.Trim();

            if (!Directory.Exists(strCheckDir))
            {
                MessageBox.Show("Check Dir not exist:" + strCheckDir);
                return;
            }

            string        strDest  = @"E:\photo\嫲嫲\renamed";
            List <string> lstFiles = new List <string>();
            int           cntPic   = 0;

            lstFiles.AddRange(Directory.GetFiles(strCheckDir, "*.*", SearchOption.AllDirectories));
            foreach (string itemFile in lstFiles)
            {
                if (itemFile.ToUpper().Contains(".JPG") || itemFile.ToUpper().Contains(".PNG"))
                {
                    EntPicM entPM = this.Init_fr_file(itemFile);
                    if (entPM.EquipModel == "MI NOTE Pro" || entPM.EquipModel == "SCH-N719" || entPM.EquipModel == "OPPO R11")
                    {
                        cntPic++;
                        FileInfo fi        = new FileInfo(itemFile);
                        string   dirName   = fi.Directory.Name;
                        string   subFolder = Path.Combine(strDest, entPM.EquipModel);
                        if (!Directory.Exists(subFolder))
                        {
                            Directory.CreateDirectory(subFolder);
                        }
                        string destName = Path.Combine(subFolder, fi.Name);
                        File.Move(itemFile, destName);

                        if (cntPic % 100 == 0)
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("process picture:{0}", cntPic));
                        }
                    }
                }
            }

            MessageBox.Show("OK");
        }
コード例 #3
0
ファイル: frmMain.cs プロジェクト: waiwong/MyCSharpProjects
        private void txtDir_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.dgvResult.DataSource = null;
                if (this.chkPic.Checked)
                {
                    #region Picture

                    string strDir = this.txtDir.Text.Trim();
                    Dictionary<string, DateTime> dicFiles = new Dictionary<string, DateTime>();
                    if (Directory.Exists(strDir))
                    {
                        listPicM.Clear();
                        string[] strFiles = Directory.GetFiles(strDir, "*.jp*g", SearchOption.AllDirectories);
                        foreach (string itemFile in strFiles)
                        {
                            if (!itemFile.Contains("/2008/") && !itemFile.Contains("/2009/")
                                && !itemFile.Contains("/2010/") && !itemFile.Contains("/2011/")
                                && !itemFile.Contains("/BackUp/") && !itemFile.Contains("/Other/")
                                && !itemFile.Contains("NoTime") && !itemFile.Contains("幼儿园"))
                            {
                                EntPicM entPM = new EntPicM();
                                entPM.FileFullName = itemFile;

                                using (FileStream stream = new FileStream(itemFile, FileMode.Open, FileAccess.Read))
                                {
                                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(stream, true, false))
                                    {
                                        entPM.Width = image.Width;
                                        entPM.Higth = image.Height;
                                        StringBuilder sbOther = new StringBuilder();
                                        Encoding ascii = Encoding.ASCII;
                                        foreach (PropertyItem p in image.PropertyItems)
                                        {
                                            switch (p.Id)
                                            {
                                                case 0x9004:
                                                    entPM.TakeTime1 = ascii.GetString(p.Value);
                                                    break;
                                                case 0x132:
                                                    entPM.TakeTime = ascii.GetString(p.Value);
                                                    break;
                                                case 0x9003:
                                                    entPM.TakeTime2 = ascii.GetString(p.Value);
                                                    break;
                                                //case 0x100:
                                                //    entPM.ImageWidth = p.Type.ToString();
                                                //    break;
                                                //case 0x101:
                                                //    entPM.ImageHigth = p.Type.ToString();
                                                //    break;
                                                case 0x110:
                                                    entPM.EquipModel = ascii.GetString(p.Value);
                                                    break;
                                                //case 0xa002:
                                                //    entPM.ExifImageWidth = convertToInt16U(p.Value);
                                                //    break;
                                                //case 0xa003:
                                                //    entPM.ExifImageHeight = convertToInt16U(p.Value);
                                                //    break;
                                                default:
                                                    if (p.Type == 0x2)
                                                    {
                                                        sbOther.AppendFormat("{0}:{1};", p.Id.ToString("x"), ascii.GetString(p.Value));
                                                    }
                                                    else if (p.Type == 0x3)
                                                    {
                                                        switch (p.Id)
                                                        {
                                                            case 0x8827:
                                                            case 0xA217:
                                                            case 0x8822:
                                                            case 0x9207:
                                                            case 0x9208:
                                                            case 0x9209:
                                                                break;
                                                            default:
                                                                sbOther.AppendFormat("{0}:{1}||", p.Id.ToString("x"), convertToInt16U(p.Value));
                                                                break;
                                                        }
                                                    }
                                                    break;
                                            }
                                        }

                                        entPM.Other = sbOther.ToString();
                                    }
                                }

                                if (entPM.TakeTime2 == null || string.IsNullOrEmpty(entPM.TakeTime2.ToString()))
                                {
                                    if (!(entPM.TakeTime1 == null || string.IsNullOrEmpty(entPM.TakeTime1.ToString())))
                                        entPM.TakeTime2 = entPM.TakeTime1;
                                }

                                if (!(entPM.TakeTime2 == null || string.IsNullOrEmpty(entPM.TakeTime2.ToString())))
                                    entPM.TakeTime = entPM.TakeTime2;

                                if (entPM.TakeTime == null || string.IsNullOrEmpty(entPM.TakeTime.ToString())
                                    || entPM.TakeTime.ToString().Equals(@"\0") || entPM.TakeTime.ToString().Length < 4)
                                {
                                    FileInfo fi = new FileInfo(itemFile);
                                    File.Copy(itemFile, Path.Combine(this.rootDisk, @"NoTime\" + fi.Name), true);

                                    entPM.TakeTime = File.GetLastWriteTime(itemFile).ToString("yyyyMMddHHmmss");
                                }

                                string strTakeTime = entPM.TakeTime.ToString().Replace(":", "");
                                if (entPM.TakeTime.ToString().Length > 10)
                                    strTakeTime = entPM.TakeTime.ToString().Substring(0, 10).Replace(":", "");
                                if (strTakeTime.CompareTo("20121001") > 0)
                                    listPicM.Add(entPM);
                            }
                        }
                    }

                    foreach (KeyValuePair<string, DateTime> kvp in dicFiles)
                    {
                        //File.SetLastWriteTime(kvp.Key, kvp.Value);
                    }

                    this.dgvResult.DataSource = listPicM;
                    #endregion
                }
                else
                {
                    string strDir = this.txtDir.Text.Trim();
                    if (Directory.Exists(strDir))
                    {
                        listVedioM.Clear();
                        string[] strFiles = Directory.GetFiles(strDir, "*.*", SearchOption.AllDirectories);
                        foreach (string itemFile in strFiles)
                        {
                            if (itemFile.ToUpper().Contains(".JPG") || itemFile.Contains("幼儿园") || itemFile.Contains("Thumbs.db"))
                            {
                                continue;
                            }

                            EntVedioM entVM = new EntVedioM();
                            entVM.FileFullName = itemFile;
                            entVM.LastModifyDT = File.GetLastWriteTime(itemFile);
                            string dateStr = entVM.LastModifyDT.ToString("yyyyMMddHHmmss");
                            if (entVM.FileName.Replace("VID_", "").Replace("meipai_", string.Empty).Replace("_", "").StartsWith(dateStr.Substring(0, 11)))
                            {
                                dateStr = entVM.FileName.Replace("VID_", "").Replace("(", "_").Replace(")", "");
                                if (dateStr.Substring(8, 1).Equals("_"))
                                {
                                    dateStr = dateStr.Substring(0, 8) + dateStr.Substring(9);
                                }
                            }
                            else if (entVM.FileName.StartsWith("meipai_"))
                            {
                                dateStr = entVM.FileName.Replace("meipai_", string.Empty);
                            }

                            entVM.FileNameDate = dateStr;
                            //if (dateStr.CompareTo("20121001") > 0)
                            listVedioM.Add(entVM);
                        }
                    }

                    this.dgvResult.DataSource = listVedioM;
                }
            }
        }
コード例 #4
0
        private void txtDir_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                bool showInfo = this.ckbShowInfo.Checked;
                this.dgvResult.DataSource = null;
                string strDir = this.txtDir.Text.Trim();
                if (!Directory.Exists(strDir))
                {
                    MessageBox.Show("Dir not exist:" + strDir);
                    return;
                }

                if (this.chkPic.Checked)
                {
                    #region Picture
                    List <EntPicM> lstPicM = new List <EntPicM>();
                    //Dictionary<string, DateTime> dicFiles = new Dictionary<string, DateTime>();
                    listPicM.Clear();
                    string[] strFiles = Directory.GetFiles(strDir, "*.jp*g", SearchOption.AllDirectories);
                    int      cnt      = 0;
                    foreach (string itemFile in strFiles)
                    {
                        if (!itemFile.Contains("/2008/") && !itemFile.Contains("/2009/") &&
                            !itemFile.Contains("/2010/") && !itemFile.Contains("/2011/") &&
                            !itemFile.Contains("/BackUp/") && !itemFile.Contains("/Other/") &&
                            !itemFile.Contains("NoTime") && !itemFile.Contains("幼儿园"))
                        {
                            EntPicM entPM = this.Init_fr_file(itemFile);
                            //if (entPM.TakeTime_string.CompareTo("20121001") > 0)
                            lstPicM.Add(entPM);
                        }

                        if (lstPicM.Count > 100)
                        {
                            if (showInfo)
                            {
                                this.listPicM.AddRange(lstPicM);
                                break;
                            }
                            else
                            {
                                cnt += lstPicM.Count;
                                this.DoSavePic(lstPicM);
                                System.Diagnostics.Debug.WriteLine(string.Format("process:{0}", cnt));
                                lstPicM.Clear();
                            }
                        }
                    }

                    //foreach (KeyValuePair<string, DateTime> kvp in dicFiles)
                    //{
                    //    //File.SetLastWriteTime(kvp.Key, kvp.Value);
                    //}

                    if (showInfo)
                    {
                        this.dgvResult.DataSource = listPicM;
                    }
                    else
                    {
                        this.DoSavePic(lstPicM);
                        MessageBox.Show("OK");
                    }

                    #endregion
                }
                else
                {
                    listVedioM.Clear();
                    List <EntVedioM> lstVedioM = new List <EntVedioM>();
                    string[]         strFiles  = Directory.GetFiles(strDir, "*.*", SearchOption.AllDirectories);
                    foreach (string itemFile in strFiles)
                    {
                        if (itemFile.ToUpper().Contains(".JPG") || itemFile.ToUpper().Contains(".PNG") || itemFile.Contains("幼儿园") || itemFile.Contains("Thumbs.db"))
                        {
                            continue;
                        }

                        if (!itemFile.ToUpper().Contains(".MP4") && !itemFile.ToUpper().Contains(".MOV"))
                        {
                            continue;
                        }

                        EntVedioM entVM = Vedio_Init_fr_File(itemFile);
                        //if (dateStr.CompareTo("20121001") > 0)
                        lstVedioM.Add(entVM);
                        if (lstVedioM.Count > 100)
                        {
                            if (showInfo)
                            {
                                this.listVedioM.AddRange(lstVedioM);
                                break;
                            }
                            else
                            {
                                this.DoSaveVideo(lstVedioM);
                                System.Diagnostics.Debug.WriteLine(string.Format("process:{0}", lstVedioM.Count));
                                lstVedioM.Clear();
                            }
                        }
                    }

                    if (ckbShowInfo.Checked)
                    {
                        this.dgvResult.DataSource = lstVedioM;
                    }
                    else
                    {
                        this.DoSaveVideo(lstVedioM);
                        MessageBox.Show("OK");
                    }
                }
            }
        }
コード例 #5
0
        private EntPicM Init_fr_file(string fileFullName)
        {
            EntPicM entPM = new EntPicM();

            entPM.FileFullName = fileFullName;

            using (FileStream stream = new FileStream(fileFullName, FileMode.Open, FileAccess.Read))
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromStream(stream, true, false))
                {
                    entPM.Width = image.Width;
                    entPM.Higth = image.Height;
                    StringBuilder sbOther = new StringBuilder();
                    Encoding      ascii   = Encoding.ASCII;
                    foreach (PropertyItem p in image.PropertyItems)
                    {
                        switch (p.Id)
                        {
                        case 0x9004:
                            entPM.TakeTime1 = ascii.GetString(p.Value);
                            break;

                        case 0x132:
                            entPM.TakeTime = ascii.GetString(p.Value);
                            break;

                        case 0x9003:
                            entPM.TakeTime2 = ascii.GetString(p.Value);
                            break;

                        //case 0x100:
                        //    entPM.ImageWidth = p.Type.ToString();
                        //    break;
                        //case 0x101:
                        //    entPM.ImageHigth = p.Type.ToString();
                        //    break;
                        case 0x110:
                            entPM.EquipModel = ascii.GetString(p.Value).Replace("\0", string.Empty);
                            break;

                        //case 0xa002:
                        //    entPM.ExifImageWidth = convertToInt16U(p.Value);
                        //    break;
                        //case 0xa003:
                        //    entPM.ExifImageHeight = convertToInt16U(p.Value);
                        //    break;
                        default:
                            if (p.Type == 0x2)
                            {
                                sbOther.AppendFormat("{0}:{1};", p.Id.ToString("x"), ascii.GetString(p.Value));
                            }
                            else if (p.Type == 0x3)
                            {
                                switch (p.Id)
                                {
                                case 0x8827:
                                case 0xA217:
                                case 0x8822:
                                case 0x9207:
                                case 0x9208:
                                case 0x9209:
                                    break;

                                default:
                                    sbOther.AppendFormat("{0}:{1}||", p.Id.ToString("x"), convertToInt16U(p.Value));
                                    break;
                                }
                            }
                            break;
                        }
                    }

                    entPM.Other = sbOther.ToString();
                }
            }

            if (entPM.TakeTime2 == null || string.IsNullOrEmpty(entPM.TakeTime2.ToString()))
            {
                if (!(entPM.TakeTime1 == null || string.IsNullOrEmpty(entPM.TakeTime1.ToString())))
                {
                    entPM.TakeTime2 = entPM.TakeTime1;
                }
            }

            if (!(entPM.TakeTime2 == null || string.IsNullOrEmpty(entPM.TakeTime2.ToString())))
            {
                entPM.TakeTime = entPM.TakeTime2;
            }

            if (entPM.TakeTime == null || string.IsNullOrEmpty(entPM.TakeTime.ToString()) ||
                entPM.TakeTime.ToString().Equals(@"\0") || entPM.TakeTime.ToString().Length < 4)
            {
                FileInfo fi = new FileInfo(fileFullName);
                entPM.TakeTime = File.GetLastWriteTime(fileFullName).ToString("yyyyMMddHHmmss");
            }

            entPM.TakeTime_string = entPM.TakeTime.ToString().Replace(":", "");
            if (entPM.TakeTime.ToString().Length > 10)
            {
                entPM.TakeTime_string = entPM.TakeTime.ToString().Substring(0, 10).Replace(":", "");
            }

            return(entPM);
        }