-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
127 lines (124 loc) · 4.27 KB
/
App.xaml.cs
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
using CefSharp;
using CefSharp.Wpf;
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BlocklyMirai
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
public App()
{
var settings = new CefSettings()
{
CachePath = Path.Combine(Environment.CurrentDirectory, "cache")
};
//settings.CefCommandLineArgs.Add("disable-gpu", "1");
settings.Locale = "zh-CN";
settings.UserAgent = "BlocklyMirai/" + Assembly.GetExecutingAssembly().GetName().Version.ToString();
settings.DisableGpuAcceleration();
if (!Cef.IsInitialized)
{
Cef.Initialize(settings);
}
}
public static string UrlEncode(string str)
{
string result = "";
foreach (byte b in Encoding.UTF8.GetBytes(str))
{
result = result + "%" + Convert.ToString(b, 16);
}
return result;
}
public static void CheckDir(string path)
{
if (!Directory.Exists(Environment.CurrentDirectory + "\\" + path.Replace("/", "\\"))) Directory.CreateDirectory(Environment.CurrentDirectory + "\\" + path.Replace("/", "\\"));
}
public static string UnZip(Stream zip, string fileDir)
{
string rootFile = "";
try
{
if (!Directory.Exists(fileDir))
{
Directory.CreateDirectory(fileDir);
}
ZipInputStream inputstream = new ZipInputStream(zip);
ZipEntry entry;
string path = fileDir;
string rootDir = "";
while ((entry = inputstream.GetNextEntry()) != null)
{
rootDir = Path.GetDirectoryName(entry.Name);
if (rootDir.IndexOf("\\") >= 0)
{
rootDir = rootDir.Substring(0, rootDir.IndexOf("\\") + 1);
}
string dir = Path.GetDirectoryName(entry.Name);
string fileName = Path.GetFileName(entry.Name);
if (dir != "")
{
if (!Directory.Exists(fileDir + "\\" + dir))
{
path = fileDir + "\\" + dir;
Directory.CreateDirectory(path);
}
}
else if (dir == "" && fileName != "")
{
path = fileDir;
rootFile = fileName;
}
else if (dir != "" && fileName != "")
{
if (dir.IndexOf("\\") > 0)
{
path = fileDir + "\\" + dir;
}
}
if (dir == rootDir)
{
path = fileDir + "\\" + rootDir;
}
if (fileName != String.Empty)
{
FileStream fs = File.Create(path + "\\" + fileName);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = inputstream.Read(data, 0, data.Length);
if (size > 0)
{
fs.Write(data, 0, size);
}
else
{
break;
}
}
fs.Close();
}
}
inputstream.Close();
return rootFile;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}