黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter.HideOption
{
    /// <summary>
    /// 查看全部文件
    /// </summary>
    public class HideOptionSearchAllFile : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 解密
        /// </summary>
        private bool decryptPassword = false;
        private string nowDirectory = string.Empty;
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm(string directory)
        {
            this.nowDirectory = directory;
            //设置头部信息
            base.SetTitleText("文件列表");
 
            var btnButton = new NormalViewControl(200, 69, true);
            btnButton.Gravity = Gravity.CenterVertical;
            btnButton.X = bodyFrameLayout.Width - Application.GetRealWidth(200) - HdlControlResourse.XXLeft;
            btnButton.TextColor = UserCenterColor.Current.TopLayoutTitleText;
            btnButton.TextAlignment = TextAlignment.BottomRight;
            btnButton.TextSize = 17;
            btnButton.Text = "翻译";
            topFrameLayout.AddChidren(btnButton);
            btnButton.ButtonClickEvent += (sender, e) =>
            {
                if (this.decryptPassword == false)
                {
                    this.decryptPassword = true;
                    //初始化中部信息
                    this.InitMiddleFrame(nowDirectory);
                }
            };
 
            //初始化中部信息
            this.InitMiddleFrame(nowDirectory);
 
            this.BackButtonClickEvent = (btnContr) =>
            {
                string rootPath = Shared.IO.FileUtils.RootPath.Trim('/');
                if (this.nowDirectory.Trim('/') == rootPath)
                {
                    this.CloseForm();
                    return;
                }
                string[] Arry = this.nowDirectory.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                string nextDir = string.Empty;
                for (int i = 0; i < Arry.Length - 1; i++)
                {
                    nextDir += Arry[i] + "/";
                }
                //初始化中部信息
                this.InitMiddleFrame(nextDir);
            };
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame(string directory)
        {
            this.nowDirectory = directory;
            this.ClearBodyFrame();
 
            var listDirectory = new List<string>();
            var listAllFile = new List<string>();
 
            //string rootPath = Shared.IO.FileUtils.RootPath.Trim('/');
            //if (this.nowDirectory.Trim('/') == rootPath)
            //{
            //    //根目录只要两个就可以了
            //    listDirectory.Add(Common.Config.Instance.Guid);
            //    listDirectory.Add(Application.Skin != null ? Application.Skin : "Phone");
            //}
            //else
            {
                var files = System.IO.Directory.GetDirectories(directory);
                foreach (var file in files)
                {
                    string[] arry = file.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                    listDirectory.Add(arry[arry.Length - 1]);
                }
                listDirectory.Sort();
 
                listAllFile = HdlFileLogic.Current.GetFileFromDirectory(directory.TrimEnd('/'));
                listAllFile.Sort();
            }
 
            var listView = new VerticalListControl(23);
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
 
            if (listDirectory.Count > 0)
            {
                var row1 = new RowLayoutControl(listView.rowSpace / 2);
                listView.AddChidren(row1);
                row1.frameTable.UseClickStatu = false;
                row1.frameTable.AddLeftCaption("【文件夹列表】", 800);
 
                for (int i = 0; i < listDirectory.Count; i++)
                {
                    this.AddDirectoryRowControl(listView, listDirectory[i], directory, i != listDirectory.Count - 1);
                }
            }
 
            if (listAllFile.Count > 0)
            {
                var row1 = new RowLayoutControl(listView.rowSpace / 2);
                listView.AddChidren(row1);
                row1.frameTable.UseClickStatu = false;
                row1.frameTable.AddLeftCaption("【文件列表】", 800);
                for (int i = 0; i < listAllFile.Count; i++)
                {
                    this.AddFileRowControl(listView, listAllFile[i], directory, i != listAllFile.Count - 1);
                }
            }
            listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(50));
 
            var btnButon = new BottomClickButton();
            btnButon.Text = "删除文件夹";
            bodyFrameLayout.AddChidren(btnButon);
            btnButon.ButtonClickEvent += (sender, e) =>
            {
                this.ShowMassage(ShowMsgType.Confirm, "是否清除该文件夹", () =>
                {
                    try
                    {
                        System.IO.Directory.Delete(directory, true);
                        this.CloseForm();
                    }
                    catch (Exception ex)
                    {
                        this.ShowMassage(ShowMsgType.Error, "清除缓存文件夹异常");
                        HdlLogLogic.Current.WriteLog(ex, "清除缓存文件夹异常");
                    }
                });
            };
            if (directory == Common.Config.Instance.FullPath)
            {
                btnButon.CanClick = false;
            }
        }
 
        private void AddDirectoryRowControl(VerticalListControl listView, string directoryName, string directory, bool addLine)
        {
            string dirNewName = directoryName;
            if (decryptPassword == true)
            {
                try
                {
                    dirNewName = HdlCommonLogic.Current.DecryptPassword(HdlUserCenterResourse.FileEncryptKey, directoryName);
                }
                catch { dirNewName = directoryName; }
            }
 
            var row1 = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(row1);
            var btnName = row1.frameTable.AddLeftCaption(dirNewName, 800);
            btnName.IsMoreLines = true;
            if (addLine == true)
            {
                row1.frameTable.AddBottomLine();
            }
            row1.frameTable.AddRightArrow();
 
            row1.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //初始化中部信息
                this.decryptPassword = false;
                this.InitMiddleFrame(System.IO.Path.Combine(directory, directoryName));
            };
        }
 
        private void AddFileRowControl(VerticalListControl listView, string fileName, string directory, bool addLine)
        {
            string fileNewName = fileName;
            if (decryptPassword == true && fileName.StartsWith("Device_") == false)
            {
                try
                {
                    fileNewName = HdlCommonLogic.Current.DecryptPassword(HdlUserCenterResourse.FileEncryptKey, fileName);
                }
                catch { fileNewName = fileName; }
            }
 
            var row1 = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(row1);
            var btnName = row1.frameTable.AddLeftCaption(fileNewName, 800);
            btnName.IsMoreLines = true;
            if (addLine == true)
            {
                row1.frameTable.AddBottomLine();
            }
            row1.frameTable.AddRightArrow();
 
            var btnReName = row1.AddDeleteControl();
            btnReName.Text = "重命名";
            btnReName.ButtonClickEvent += (sender, e) =>
            {
                //生成一个弹窗画面
                var dialogForm = new DialogInputControl(360);
                //保存模板到App
                dialogForm.SetTitleText("重命名");
                //请输入新名字
                dialogForm.SetTipText("请输入新名字");
                dialogForm.Text = fileName;
 
                //按下确认按钮
                dialogForm.ComfirmClickEvent += ((textValue) =>
                {
                    //画面关闭
                    dialogForm.CloseDialog();
                    if (textValue == string.Empty)
                    {
                        return;
                    }
                    HdlFileLogic.Current.MoveFile(System.IO.Path.Combine(directory, fileName), System.IO.Path.Combine(directory, textValue));
 
                    fileNewName = textValue;
                    fileName = textValue;
                    btnName.Text = textValue;
                });
            };
 
            var btnUpLoad = row1.AddEditorControl();
            btnUpLoad.Text = "上传";
            btnUpLoad.ButtonClickEvent += (sender, e) =>
            {
                this.ShowMassage(ShowMsgType.Confirm, "是否上传该文件(测试)?", () =>
                {
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        string tagrtFile = System.IO.Path.Combine(directory, fileName);
                        HdlBackupLogic.Current.UpLoadByteDataToOptionBackup(fileNewName, HdlFileLogic.Current.ReadFileByteContent(tagrtFile));
                    });
                });
            };
 
            var btnDelete = row1.AddDeleteControl();
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                this.ShowMassage(ShowMsgType.Confirm, "是否清除该缓存文件", () =>
                {
                    var myFile = System.IO.Path.Combine(directory, fileName);
                    try
                    {
                        System.IO.File.Delete(myFile);
                        row1.RemoveFromParent();
                    }
                    catch (Exception ex)
                    {
                        this.ShowMassage(ShowMsgType.Error, "清除缓存文件异常");
                        HdlLogLogic.Current.WriteLog(ex, "清除缓存文件异常");
                    }
                });
            };
 
            row1.frameTable.ButtonClickEvent += (sender, e) =>
            {
                var form = new HideOptionFileContentForm();
                form.AddForm(System.IO.Path.Combine(directory, fileName));
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        #endregion
    }
}