예제 #1
0
        //@brief 加载任务
        public void LoadTask(ListView ls)
        {
            if (!_init)
            {
                return;
            }
            string value = _appTasks.GetValue("Tasks");

            if (string.IsNullOrEmpty(value))
            {
                return;
            }
            ls.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            string[] arr = value.Split(';');
            foreach (string s in arr)
            {
                string[] arr2 = s.Split(',');
                if (arr2.Length != 2)
                {
                    continue;
                }
                ListViewItem lvi = new ListViewItem();
                lvi.Tag = arr2[0];
                string filePath = arr2[0];

                lvi.Text = SynCommon.ShortFilePath(filePath);
                lvi.SubItems.Add(arr2[1]);
                ls.Items.Add(lvi);
            }
            ls.EndUpdate();  //结束数据处理,UI界面一次性绘制。
        }
예제 #2
0
파일: CSynFiles.cs 프로젝트: dyc0113/learn
        public void SynFile(string fileFullName, string linuxDir)
        {
            if (!File.Exists(fileFullName))  // 文件不存在。
            {
                return;
            }
            if (fileFullName.LastIndexOf('\\') == fileFullName.Length - 1)
            {
                _mainForm.Log("不支持同步目录");
                return;
            }
            System.IO.FileInfo file = new System.IO.FileInfo(fileFullName);
            if (file.Length > N)
            {
                MessageBox.Show("同步的文件过大" + fileFullName);
                return;
            }
            _mainForm.Log(SynCommon.ShortFilePath(fileFullName) + " -> " + linuxDir);
            try
            {
                // 判断文件编码方式
                Encoding     encode = EncodingType.GetType(fileFullName);
                StreamReader srNew  = null;
                if (encode != Encoding.UTF8)
                {
                    srNew = new StreamReader(fileFullName, Encoding.Default);
                }
                else
                {
                    srNew = new StreamReader(fileFullName, Encoding.UTF8);
                }

                string con = srNew.ReadToEnd();
                // 把windows换行符转换成linux换行符
                con = con.Replace("\r\n", "\n");
                // 如果文件名称后缀已.cpp .h 结尾 则 转换成utf8编码
                if (fileFullName.ToLower().EndsWith(".cpp") ||
                    fileFullName.ToLower().EndsWith(".h") ||
                    fileFullName.ToLower().EndsWith(".jce")
                    )
                {
                    if (encode != Encoding.UTF8)
                    {
                        con = CFileComm.gb2312_utf8(con);
                    }
                }
                srNew.Close();
                UInt64 last_update_tm = SynCommon.ToUTCSec(file.LastWriteTime);
                FillMessage(linuxDir, file.Name, last_update_tm, con);
                // 想服务器发送数据
                SendData(_sendData);
                RecevData();
            }
            catch (IOException e)
            {
                _mainForm.Log(e.ToString());
            }
        }
예제 #3
0
파일: Main_Form.cs 프로젝트: dyc0113/learn
        private void ForeachTree(TreeNode node, string dir, int flag = 1)
        {
            string filePath = node.Tag as string;

            if (flag == 1)
            {
                // 添加到任务中
                if (node.Checked && SynCommon.IsFile(filePath))
                {
                    bool isExist = false;
                    foreach (ListViewItem it in lvTask.Items)
                    {
                        string fullPath = it.Tag as string;
                        if (fullPath == filePath)
                        {
                            isExist = true;
                        }
                    }
                    if (!isExist)// 如果文件不在里面, 则添加
                    {
                        // 添加到
                        this.lvTask.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
                        ListViewItem lvi = new ListViewItem();
                        lvi.Tag  = filePath;
                        lvi.Text = SynCommon.ShortFilePath(filePath);

                        lvi.SubItems.Add(dir);
                        this.lvTask.Items.Add(lvi);

                        this.lvTask.EndUpdate();  //结束数据处理,UI界面一次性绘制。
                    }
                }
            }
            else if (flag == 2)// 刷新目录树
            {
                bool isExist = false;
                foreach (ListViewItem it in lvTask.Items)
                {
                    string fullPath = it.Tag as string;
                    if (fullPath == filePath)
                    {
                        isExist = true;
                    }
                }
                if (isExist)
                {
                    node.Checked = true;
                }
                else
                {
                    node.Checked = false;
                }
            }
            else if (flag == 3) // 选中listView
            {
                if (lvTask.SelectedItems.Count > 0)
                {
                    string fullName = lvTask.SelectedItems[0].Tag as string;
                    if (filePath == fullName)
                    {
                        node.EnsureVisible();
                    }
                }
            }
            else if (flag == 4)// 保存每个节点的展开结构
            {
                _mTreeExpand[node.Tag as string] = node.IsExpanded;
                if (node.IsSelected)   // 记录选中节点的Tag路径
                {
                    _selectNodeTag = node.Tag as string;
                }
            }
            else if (flag == 5)// 回复每个节点的展开结构
            {
                bool value = false;
                if (_mTreeExpand.TryGetValue(node.Tag as string, out value))
                {
                    if (value)
                    {
                        node.Expand();
                    }
                }
                if (node.Tag as string == _selectNodeTag)
                {
                    node.EnsureVisible();
                }
            }
            foreach (TreeNode n in node.Nodes)
            {
                ForeachTree(n, dir, flag);
            }
        }