Beispiel #1
0
 private void BtBuild_Click(object sender, EventArgs e)
 {
     Task.Factory.StartNew(() =>
     {
         this.Invoke(new Action(() => { LbResult.Text = "开始检索并生成目录文件,请稍候……"; }));
         beginTime          = DateTime.Now;
         string path        = TbPath.Text;
         string parentPath  = DirTool.Parent(path);
         FileCodeTool fcode = new FileCodeTool();
         if (Directory.Exists(path) && Directory.Exists(parentPath))
         {
             List <string> fileList = FileTool.GetAllFile(path);
             if (!ListTool.IsNullOrEmpty(fileList))
             {
                 VersionModel version = new VersionModel()
                 {
                     Number = DateTime.Now.Second, Path = path, FileList = new List <VersionFile>(),
                 };
                 foreach (var item in fileList)
                 {
                     version.FileList.Add(new VersionFile()
                     {
                         File = item.Replace(path, ""),
                         MD5  = fcode.GetMD5(item),
                     });
                 }
                 string file = string.Format(@"{0}\version.txt", parentPath);
                 string json = JsonTool.ToStr(version);
                 TxtTool.Create(file, json);
             }
         }
         endTime = DateTime.Now;
         this.Invoke(new Action(() => { LbResult.Text = string.Format("生成完成,用时:{0:f2} 毫秒。", (endTime - beginTime).TotalMilliseconds); }));
     });
 }
Beispiel #2
0
        private void BtAddFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                FileCodeTool fc = new FileCodeTool();
                DgFileList.Rows.Add(new object[] {
                    fileDialog.FileName, fileDialog.FileName,
                    fc.GetMD5(fileDialog.FileName), false
                });
            }
        }
Beispiel #3
0
        const string Unknown = "Un";//未知型号相机

        /// <summary>
        /// 创建照片信息模型
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static Pictures CreateModel(string file)
        {
            try
            {
                DateTime createTime = File.GetCreationTime(file);
                DateTime writeTime  = File.GetLastWriteTime(file);

                FileCodeTool codetool = new FileCodeTool();
                string       md5      = codetool.GetMD5(file);
                string       sha1     = codetool.GetSHA1(file);

                Pictures picture = new Pictures()
                {
                    Id       = GuidTool.Short(),
                    ExtName  = Path.GetExtension(file).ToUpper(),
                    MD5      = md5,
                    SHA1     = sha1,
                    OrigTime = createTime < writeTime ? createTime : writeTime,
                };

                using (ExifHelper ex = new ExifHelper(file))
                {
                    string maker = ex.GetPropertyString((int)ExifTagNames.EquipMake).Trim().Replace(" ", "_");
                    string model = ex.GetPropertyString((int)ExifTagNames.EquipModel).Trim().Replace(" ", "_");
                    picture.Model = (Str.Ok(maker) ? maker : Unknown) + "@" + (Str.Ok(model) ? model : Unknown);

                    char GpsLongitudeRef = ex.GetPropertyChar((int)ExifTagNames.GpsLongitudeRef);
                    char GpsLatitudeRef  = ex.GetPropertyChar((int)ExifTagNames.GpsLatitudeRef);
                    picture.GpsLongitude = ex.GetPropertyDouble((int)ExifTagNames.GpsLongitude) * (GpsLongitudeRef.Equals('E') ? 1 : -1);
                    picture.GpsLatitude  = ex.GetPropertyDouble((int)ExifTagNames.GpsLatitude) * (GpsLatitudeRef.Equals('N') ? 1 : -1);

                    string[] exifDTOrig = ex.GetPropertyString((int)ExifTagNames.ExifDTOrig).Trim().Split(' ');
                    if (exifDTOrig != null && exifDTOrig.Count() == 2)
                    {
                        if (DateTime.TryParse(string.Format("{0} {1}", exifDTOrig[0].Replace(':', '-'), exifDTOrig[1]), out DateTime dt))
                        {
                            picture.OrigTime = dt;
                        }
                    }
                    picture.Name = string.Format("{0}-{1}{2}", picture.OrigTime.ToString("yyyyMMddhhmmss"), picture.MD5, picture.ExtName);
                }
                return(picture);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 下载程序文件
 /// </summary>
 /// <returns></returns>
 bool DownloadFile(string downloadPath)
 {
     if (DirTool.Create(downloadPath))
     {
         FileCodeTool fcode = new FileCodeTool();
         for (int i = 0; i < version.FileList.Count; i++)
         {
             string fileName   = Path.GetFileName(version.FileList[i].File);
             string sourceFile = version.ServerPath + version.FileList[i].File;
             string destFile   = downloadPath + version.FileList[i].File;
             string destPath   = destFile.Substring(0, destFile.Length - fileName.Length);
             if (DirTool.Create(destPath))
             {
                 if (File.Exists(R.AppPath + version.FileList[i].File) &&
                     version.FileList[i].MD5 == fcode.GetMD5(R.AppPath + version.FileList[i].File))
                 {
                     UIDgvFileListUpdate(i, "ColDown", R.cst.FILE_JUMP);
                 }
                 else
                 {
                     FtpTool ftp = new FtpTool(R.FtpIp, R.FtpAccount, R.FtpPassword);
                     if (!ftp.DownloadFile(sourceFile, destPath))
                     {
                         if (!ftp.DownloadFile(sourceFile, destPath))
                         {
                             if (!ftp.DownloadFile(sourceFile, destPath))
                             {
                                 MessageBox.Show("更新文件无法被下载,请检查网络重试,谢谢。", "网络故障");
                                 Step  = 5;
                                 Error = -201;
                                 return(false);
                             }
                         }
                     }
                     UIDgvFileListUpdate(i, "ColDown", R.cst.FILE_SUCC);
                 }
             }
             else
             {
                 UIDgvFileListUpdate(i, "ColDown", R.cst.FILE_FAIL);
             }
             Thread.Sleep(R.cst.WAIT_TIME);
         }
     }
     Step = 3;
     return(true);
 }
Beispiel #5
0
 /// <summary>
 /// 下载程序文件
 /// </summary>
 /// <returns></returns>
 bool DownloadFile(string downloadPath)
 {
     if (DirTool.Create(downloadPath))
     {
         FileCodeTool fcode = new FileCodeTool();
         for (int i = 0; i < version.FileList.Count; i++)
         {
             string fileName   = Path.GetFileName(version.FileList[i].File);
             string sourceFile = version.Path + version.FileList[i].File;
             string destFile   = downloadPath + version.FileList[i].File;
             string destPath   = destFile.Substring(0, destFile.Length - fileName.Length);
             if (DirTool.Create(destPath))
             {
                 try
                 {
                     if (File.Exists(AppDir + version.FileList[i].File) &&
                         version.FileList[i].MD5 == fcode.GetMD5(AppDir + version.FileList[i].File))
                     {
                         this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_JUMP); }));
                     }
                     else
                     {
                         //File.Copy(sourceFile, destFile);
                         FtpHelper ftp = new FtpHelper(FtpIp, FtpAccount, FtpPassword);
                         ftp.DownloadFile(sourceFile, destPath);
                         this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_SUCC); }));
                     }
                 }
                 catch (Exception e)
                 {
                     this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_FAIL); }));
                 }
             }
             else
             {
                 this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_FAIL); }));
             }
             Thread.Sleep(WAIT_TIME);
         }
     }
     return(false);
 }
Beispiel #6
0
        /// <summary>
        /// 下载要更新的文件
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        private bool UpdateDownload(VersionModel vm)
        {
            FileCodeTool fcode    = new FileCodeTool();
            var          downFile = vm.FileList.Where(x => x.IsClean == false).ToList();

            if (vm != null && ListTool.HasElements(downFile))
            {
                for (int i = 0; i < downFile.Count(); i++)
                {
                    VersionFile file       = downFile[i];
                    string      serverFile = DirTool.Combine(vm.ServerPath, file.ServerFile);
                    string      tempFile   = DirTool.Combine(R.Paths.Temp, DownTemp, file.ServerFile);                                                 //下载到目标位置(带文件名)
                    string      localFile  = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile); //旧文件位置
                    if (fcode.GetMD5(localFile) != file.FileMD5)
                    {
                        UIUpdateDetail("正在下载:" + Path.GetFileName(file.ServerFile));
                        R.Log.v(string.Format("{0} 文件有更新,正在下载文件", Path.GetFileName(file.ServerFile)));
                        FtpTool ftp = new FtpTool(R.Settings.FTP.Address, R.Settings.FTP.Account, R.Settings.FTP.Password);
                        if (!ftp.Download(serverFile, tempFile))
                        {
                            if (!ftp.Download(serverFile, tempFile))
                            {
                                if (!ftp.Download(serverFile, tempFile))
                                {
                                    R.Log.w(string.Format("{0} 文件下载失败", Path.GetFileName(file.ServerFile)));
                                    return(false);
                                }
                            }
                        }
                    }
                    else
                    {
                        UIUpdateDetail("文件已存在:" + Path.GetFileName(file.ServerFile));
                        R.Log.v(string.Format("{0} 文件不需要更新,已跳过该文件", Path.GetFileName(file.ServerFile)));
                    }
                    UIProgress(i + 1, downFile.Count());
                }
                return(true);
            }
            return(false);
        }
Beispiel #7
0
 /// <summary>
 /// 备份程序文件
 /// </summary>
 /// <returns></returns>
 bool BackupFile(string backupPath, string downloadPath)
 {
     if (DirTool.Create(backupPath))
     {
         FileCodeTool fcode = new FileCodeTool();
         for (int i = 0; i < version.FileList.Count; i++)
         {
             string fileName     = Path.GetFileName(version.FileList[i].File);
             string sourceFile   = AppDir + version.FileList[i].File;
             string destFile     = backupPath + version.FileList[i].File;
             string destPath     = destFile.Substring(0, destFile.Length - fileName.Length);
             string downloadFile = downloadPath + version.FileList[i].File;
             if (DirTool.Create(destPath))
             {
                 try
                 {
                     if (File.Exists(sourceFile) && File.Exists(downloadFile) && version.FileList[i].MD5 != fcode.GetMD5(AppDir + version.FileList[i].File))
                     {
                         File.Copy(sourceFile, destFile);
                         this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_SUCC); }));
                     }
                     else
                     {
                         this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_JUMP); }));
                     }
                 }
                 catch (Exception e)
                 {
                     this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_FAIL); }));
                 }
             }
             else
             {
                 this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_FAIL); }));
             }
             Thread.Sleep(WAIT_TIME);
         }
     }
     return(false);
 }
Beispiel #8
0
        private void CreateVersionMap()
        {
            string versionNumber = TbVersionNumber.Text;
            string ftpPath       = TbFtpPath.Text;

            string[] beginClose = TbBeginClose.Text.Split(';');
            string[] endRun     = TbEndRun.Text.Split(';');

            string       path       = TbPath.Text;
            string       parentPath = DirTool.Parent(path);
            FileCodeTool fcode      = new FileCodeTool();

            if (Directory.Exists(path) && Directory.Exists(parentPath))
            {
                List <string> fileList = FileTool.GetAllFile(path);
                if (!ListTool.IsNullOrEmpty(fileList))
                {
                    VersionModel version = new VersionModel()
                    {
                        Number            = versionNumber,
                        ServerPath        = ftpPath,
                        BeginCloseProcess = beginClose,
                        EndRunProcess     = endRun,
                        FileList          = new List <VersionFile>()
                    };

                    foreach (var item in fileList)
                    {
                        version.FileList.Add(new VersionFile()
                        {
                            File = item.Replace(path, ""),
                            MD5  = fcode.GetMD5(item),
                        });
                    }
                    string file = string.Format(@"{0}\update.version", parentPath, versionNumber);
                    string json = JsonTool.ToStr(version);
                    TxtTool.Create(file, json);
                }
            }
        }
Beispiel #9
0
        private void BtImport_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();

            dialog.Description = "请选择要导入的文件路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string        foldPath = dialog.SelectedPath;
                List <string> fileList = FileTool.GetAllFile(foldPath);
                if (ListTool.HasElements(fileList))
                {
                    FileCodeTool fc = new FileCodeTool();
                    fileList.ForEach(x =>
                    {
                        string relativePath = x.Replace(foldPath, "");
                        DgFileList.Rows.Add(new object[] {
                            relativePath, relativePath, fc.GetMD5(x), false
                        });
                    });
                }
            }
        }