Ejemplo n.º 1
0
 /// <summary>
 /// 导入文件线程
 /// </summary>
 void threadImportItems()
 {
     try
     {
         string newFileName;
         for (int i = 0; i < ItemsPath.Length; i++)
         {
             if (File.Exists(ItemsPath[i]))
             {
                 newFileName = FileTree.importFile(ItemsPath[i],
                                                   CurrentPath + "/" + Path.GetFileName(ItemsPath[i]));
                 /* 加密 */
                 CMDComand.encryptFile(newFileName, newFileName, fileKey);
                 label_fileStatus.Invoke(new MethodInvoker(delegate
                 {
                     label_fileStatus.Text = "正在处理: " + Path.GetFileName(ItemsPath[i]);
                     label_fileStatus.SetBounds(142 - (label_fileStatus.Width / 2), label_fileStatus.Location.Y, label_fileStatus.Width, label_fileStatus.Height);
                 }
                                                           ));
             }
             else if (Directory.Exists(ItemsPath[i]))
             {
                 FileTree.importDirectory(ItemsPath[i], CurrentPath + "/" + Path.GetFileName(ItemsPath[i]), label_fileStatus, fileKey);
             }
         }
         MethodInvoker methodInvoker = new MethodInvoker(closeForm);
         BeginInvoke(methodInvoker);
     }
     catch (Exception e)
     {
         Reporter.reportBug(e.ToString());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 导入文件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public static string importDirectory(string source, string destination, Label labelFileStatus, string fileKey)
        {
            if (!Directory.Exists(source))
            {
                return(null);
            }
            /* 遍历source目录下文件夹 */
            DirectoryInfo directoryInfo = new DirectoryInfo(source);

            DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
            string          newFolderName  = destination;
            /* 防止重名 */
            int counter = 0;

            while (Directory.Exists(newFolderName))
            {
                ++counter;
                newFolderName = Path.GetDirectoryName(destination) + "/" + Path.GetFileNameWithoutExtension(destination) + "_" +
                                counter.ToString();
                //string a = "";
            }
            Directory.CreateDirectory(newFolderName);
            /* 递归 */
            foreach (DirectoryInfo di in directoryInfos)
            {
                importDirectory(di.FullName, newFolderName + "/" + di.Name, labelFileStatus, fileKey);
            }
            /* 复制本目录文件 */
            FileInfo[] fileInfo = directoryInfo.GetFiles();
            foreach (FileInfo fi in fileInfo)
            {
                if (labelFileStatus != null)
                {
                    labelFileStatus.Invoke(new MethodInvoker(delegate
                    {
                        labelFileStatus.Text = "正在处理: " + fi.Name;
                        labelFileStatus.SetBounds(142 - (labelFileStatus.Width / 2), labelFileStatus.Location.Y, labelFileStatus.Width, labelFileStatus.Height);
                    }
                                                             ));
                }
                File.Copy(fi.FullName, newFolderName + "/" + fi.Name);
                /* 加密导入 */
                CMDComand.encryptFile(newFolderName + "/" + fi.Name, newFolderName + "/" + fi.Name, fileKey);
            }
            return(newFolderName);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 同步线程方法
        /// </summary>
        public void threadSync()
        {
            //setSyncFormFileStatus(SyncResult.getSyncFileResult(userLocalInfo.SyncPath), SyncResult.FileSyncStatus.Fail);
            while (true)
            {
                try
                {
                    //setCloudDiskFormSyncLabel("正在尝试同步");
                    int    tempExitCode = CMDComand.syncDirectory(userLocalInfo.SyncPath, userInfo.UserID, userInfo.Password, userInfo.SyncServerAddress);
                    string syncResult   = SyncResult.getSyncResult();
                    if (tempExitCode == 0)
                    {
                        setCloudDiskFormSyncLabel(syncResult);

                        /*
                         * if (syncResult.Equals(SyncResult.RESULT_SYNC_SUCCESS))
                         * {
                         *  //setSyncFormFileStatus(SyncResult.getSyncFileResult(userLocalInfo.SyncPath), SyncResult.FileSyncStatus.Success);
                         * }
                         * else
                         * {
                         *  //setSyncFormFileStatus(SyncResult.getSyncFileResult(userLocalInfo.SyncPath), SyncResult.FileSyncStatus.Fail);
                         * }
                         */
                    }
                    else
                    {
                        setCloudDiskFormSyncLabel("同步进程未能正常执行");
                        //setSyncFormFileStatus(SyncResult.getSyncFileResult(userLocalInfo.SyncPath), SyncResult.FileSyncStatus.Fail);
                    }
                    Thread.Sleep(2000);
                    /* 清除同步记录 */
                    SyncResult.clearSyncResult();
                    if (!isAutoSync)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    Reporter.reportBug(e.ToString());
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 导出项目
        /// </summary>
        /// <param name="itemNames"></param>
        /// <param name="keyNames"></param>
        /// <param name="destination"></param>
        public static void exportItems(Queue <string> itemNames, Queue <string> keyNames, string destination, Label labelFileStatus, string fileKey)
        {
            if (itemNames.Count != keyNames.Count)
            {
                return;
            }
            string itemName;
            string keyName;
            string fileName;

            while (itemNames.Count > 0)
            {
                itemName = itemNames.Dequeue();
                keyName  = keyNames.Dequeue();
                //调试用
                Reporter.writeLog("./log/export.log", "export " + itemName);
                if (keyName.Contains(FileTree.FILE_IDENTIFY_NAME))
                {
                    fileName = itemName + MyConfig.EXTEND_NAME_ENCRYP_FILE;
                    labelFileStatus.Invoke(new MethodInvoker(delegate
                    {
                        labelFileStatus.Text = "正在处理: " + Path.GetFileName(fileName);
                        labelFileStatus.SetBounds(142 - (labelFileStatus.Width / 2), labelFileStatus.Location.Y, labelFileStatus.Width, labelFileStatus.Height);
                    }
                                                             ));
                    /* 解密输出 */
                    if (File.Exists(fileName))
                    {
                        /* 重名检查 */
                        string destName    = destination + "/" + Path.GetFileNameWithoutExtension(fileName);
                        string oringinName = destName;
                        int    counter     = 0;
                        while (File.Exists(destName))
                        {
                            ++counter;
                            destName = destination + "/" + Path.GetFileNameWithoutExtension(oringinName) + "_" + counter + Path.GetExtension(oringinName);
                        }
                        CMDComand.discryptFile(fileName, destName, fileKey);
                    }
                    //CMDComand.discryptFile(fileName, destination + "/" + Path.GetFileName(fileName));
                }
                else if (keyName.Contains(FileTree.FOLDER_IDENTIFY_NAME))
                {
                    if (Directory.Exists(itemName))
                    {
                        string destName = destination + "/" + Path.GetFileName(itemName);

                        if (!Directory.Exists(destName))
                        {
                            Directory.CreateDirectory(destName);
                        }
                        DirectoryInfo   directoryInfo  = new DirectoryInfo(itemName);
                        DirectoryInfo[] directory_info = directoryInfo.GetDirectories();
                        FileInfo[]      fileInfo       = directoryInfo.GetFiles();
                        Queue <string>  names          = new Queue <string>();
                        Queue <string>  keys           = new Queue <string>();
                        for (int i = 0; i < fileInfo.Length; i++)
                        {
                            names.Enqueue(fileInfo[i].DirectoryName + "/" + Path.GetFileNameWithoutExtension(fileInfo[i].FullName));
                            keys.Enqueue(FileTree.FILE_IDENTIFY_NAME);
                        }
                        for (int i = 0; i < directory_info.Length; i++)
                        {
                            names.Enqueue(directory_info[i].FullName);
                            keys.Enqueue(FileTree.FOLDER_IDENTIFY_NAME);
                        }
                        /* 递归 */
                        exportItems(names, keys, destination + "/" + Path.GetFileName(itemName), labelFileStatus, fileKey);
                    }
                }
            }
        }