private void HandleMsg_Patch_GetFileList()
        {
            if (string.IsNullOrEmpty(m_CurrentFolderPath))
            {
                m_CurrentFolderPath = PatchFolder;
                if (!Directory.Exists(m_CurrentFolderPath))
                {
                    m_CurrentFolderPath = RemoteDebugUtil.GetParentPath(PatchFolder);
                }
            }
            if (!Directory.Exists(m_CurrentFolderPath))
            {
                Debug.LogError("not exist folder:" + m_CurrentFolderPath);
                return;
            }
            m_Client.Send(string.Format("{0}#{1}$",
                                        (int)RemoteDebugMsg.Patch_RemoteCurrentFolder,
                                        m_CurrentFolderPath
                                        ));
            var parent = RemoteDebugUtil.GetParentPath(m_CurrentFolderPath);

            m_Client.Send(string.Format("{0}#{1}|{2}|{3}|{4}$",
                                        (int)RemoteDebugMsg.Patch_RemoteFiles,
                                        0,
                                        "..",
                                        0,
                                        RemoteDebugUtil.GetFileLastWriteTime(parent)
                                        ));
            foreach (var path in Directory.GetDirectories(m_CurrentFolderPath))
            {
                var folder = Path.GetFileName(path);
                if (!IsSearchFileName(folder))
                {
                    continue;
                }
                m_Client.Send(string.Format("{0}#{1}|{2}|{3}|{4}$",
                                            (int)RemoteDebugMsg.Patch_RemoteFiles,
                                            1,
                                            folder,
                                            0,
                                            RemoteDebugUtil.GetFileLastWriteTime(path)
                                            ));
            }
            foreach (var path in Directory.GetFiles(m_CurrentFolderPath))
            {
                var fileName = Path.GetFileName(path);
                if (!IsSearchFileName(fileName))
                {
                    continue;
                }
                var fi = new FileInfo(path);
                m_Client.Send(string.Format("{0}#{1}|{2}|{3}|{4}$",
                                            (int)RemoteDebugMsg.Patch_RemoteFiles,
                                            2,
                                            fileName,
                                            fi.Length,
                                            fi.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss")
                                            ));
            }
        }
        private void OnGUI_Menu(Rect rect)
        {
            var btnGap = 1;
            var btnWid = 53;
            var index  = 0;

            if (GUI.Button(new Rect(rect.x + (index++) * (btnWid + btnGap), rect.y, btnWid, rect.height), Styles.btnBack))
            {
                if (!m_IsUploaded)
                {
                    RemoteDebugWindow.Instance.ShowNotification(new GUIContent("Operation not allowed: uploading ... "));
                    return;
                }
                m_LocalPath = RemoteDebugUtil.GetParentPath(m_LocalPath);
                RefreshFileList();
            }
            if (GUI.Button(new Rect(rect.x + (index++) * (btnWid + btnGap), rect.y, btnWid, rect.height), Styles.btnUpload))
            {
                if (m_WaitingUploadFileInfos.Count <= 0)
                {
                    RemoteDebugWindow.Instance.ShowNotification(new GUIContent("no selected files."));
                }
                else
                {
                    var files = string.Join("\n", m_WaitingUploadFileInfos);
                    if (EditorUtility.DisplayDialog("Upload selected files", "Upload all selected files?\n" + files, "Sure", "Cancel"))
                    {
                        UploadStart();
                        UploadNextFile();
                    }
                }
            }
            if (GUI.Button(new Rect(rect.x + (index++) * (btnWid + btnGap), rect.y, btnWid, rect.height), Styles.btnCancel))
            {
                foreach (var info in m_FileList)
                {
                    info.itemSelected = false;
                }
                m_FileTree.Repaint();
            }

            var filter = new GUIContent(Styles.iconFilter, "Filter Files:\n" + string.Join("|", m_FilterFiles));

            GUI.Button(new Rect(rect.x + rect.width - 25, rect.y, 25, rect.height), filter);
        }
 private void HandleReceiveFile()
 {
     if (!m_ReceiveFile)
     {
         return;
     }
     if (Time.time - m_LastSpeedTime >= 1)
     {
         m_LastSpeedTime = Time.time;
         m_ReceiveSpeed  = m_LastSpeedByte;
         m_LastSpeedByte = 0;
     }
     if (Time.time - m_LastCheckTime > 0.1f)
     {
         m_LastCheckTime = Time.time;
         var currSize = RemoteDebugUtil.GetFileSize(m_ReceiveFilePath);
         if (currSize == m_ReceiveFileSize)
         {
             m_ReceiveFileStream.Flush();
             m_ReceiveFileStream.Close();
             m_ReceiveFile = false;
             var md5 = RemoteDebugUtil.GetFileMd5(m_ReceiveFilePath);
             if (md5.Equals(m_ReceiveFileMd5))
             {
                 HandleMsg_Patch_GetFileList();
                 m_Client.Send(string.Format("{0}#{1}|{2}$", (int)RemoteDebugMsg.Patch_LocalUploadEnd, m_ReceiveFileName, 0));
             }
             else
             {
                 m_Client.Send(string.Format("{0}#{1}|{2}$", (int)RemoteDebugMsg.Patch_LocalUploadEnd, m_ReceiveFileName, 1));
             }
         }
         else
         {
             m_Client.Send(string.Format("{0}#{1}|{2}|{3}$",
                                         (int)RemoteDebugMsg.Patch_LocalUpload, m_ReceiveFileName, currSize, m_ReceiveSpeed));
         }
     }
 }
        public void UploadNextFile(bool flag = true, string successedFileName = null)
        {
            if (!string.IsNullOrEmpty(successedFileName))
            {
                if (flag)
                {
                    m_UploadCurrCount++;
                    m_UploadCurrSize  = 0;
                    m_UploadFileSize += (int)RemoteDebugUtil.GetFileSize(m_LocalPath + "/" + successedFileName);
                    m_Parent.UpdateLogStatus(m_LocalPath + "/" + successedFileName, "");
                    if (m_UploadFileSize == m_UploadTotalSize)
                    {
                        RemoteDebugWindow.Instance.ShowNotification(new GUIContent("Upload All File Success"));
                    }
                }
                else
                {
                    m_Parent.UpdateLogStatus(m_LocalPath + "/" + successedFileName, "failed: not same md5.");
                }
            }
            Debug.LogError("UploadNextFile:" + m_WaitingUploadFileInfos.Count);
            if (m_WaitingUploadFileInfos.Count == 0)
            {
                m_IsUploaded    = true;
                m_UploadEndTick = DateTime.Now.Ticks;
                return;
            }
            var info = m_WaitingUploadFileInfos[0];

            m_WaitingUploadFileInfos.RemoveAt(0);
            var filePath = m_LocalPath + "/" + info.name;
            var fileSize = 0L;
            var md5      = RemoteDebugUtil.GetFileMd5(filePath, out fileSize);

            server?.RequestPatchUploadStart(clientIndex, info.name, (int)fileSize, md5);
            server?.RequestPatchUploadFile(clientIndex, filePath);
            m_Parent.AddLog(filePath, (int)fileSize);
            m_IsUploading = true;
        }
 private void HandleMsg_Patch_RemoteBack()
 {
     m_CurrentFolderPath = RemoteDebugUtil.GetParentPath(m_CurrentFolderPath);
     HandleMsg_Patch_GetFileList();
 }
        private void RefreshFileList()
        {
            if (m_FileTree == null)
            {
                return;
            }
            if (!Directory.Exists(m_LocalPath))
            {
                Debug.LogError("lcoalPath not exist:" + m_LocalPath);
                return;
            }
            m_FileList.Clear();
            m_FileTotalSize  = 0;
            m_FileTotalCount = 0;

            var back   = new PatchFileInfo();
            var parent = RemoteDebugUtil.GetParentPath(m_LocalPath);

            back.name      = "..";
            back.assetPath = parent;
            back.size      = 0;
            back.type      = 0;
            back.datetime  = new FileInfo(parent).LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss");
            back.assetIcon = RemoteDebugStyles.iconFolder;
            m_FileList.Add(back);

            foreach (var path in Directory.GetDirectories(m_LocalPath))
            {
                var folder = Path.GetFileName(path);
                if (IsFilter(path) || IsFilterFolder(folder) || !IsSearchFileName(folder))
                {
                    continue;
                }
                var fi   = new FileInfo(path);
                var info = new PatchFileInfo();
                info.name      = folder;
                info.assetPath = path;
                info.size      = 0;
                info.type      = 1;
                info.datetime  = fi.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss");
                info.assetIcon = RemoteDebugStyles.iconFolder;
                m_FileList.Add(info);
                m_FileTotalCount++;
            }
            foreach (var path in Directory.GetFiles(m_LocalPath))
            {
                if (IsFilter(path))
                {
                    continue;
                }
                var fileName = Path.GetFileName(path);
                if (!IsSearchFileName(fileName))
                {
                    continue;
                }
                var fi   = new FileInfo(path);
                var info = new PatchFileInfo();
                info.name      = fileName;
                info.assetPath = path;
                info.size      = (int)fi.Length;
                info.type      = 2;
                info.datetime  = fi.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss");
                info.assetIcon = RemoteDebugStyles.iconFile;
                m_FileList.Add(info);
                m_FileTotalSize += info.size;
                m_FileTotalCount++;
            }
            m_FileTree.UpdateInfoList(m_FileList);
            Repaint();
        }