(SamsungUpdatesFetch)
26 | };
27 | FWFetchFuncs = list;
28 | }
29 |
30 | //http://fota-cloud-dn.ospserver.net
31 | public static string FOTAInfoFetch(string model, string region, bool latest)
32 | {
33 | try
34 | {
35 | using (WebClient client = new WebClient())
36 | {
37 | string xml = client.DownloadString("http://fota-cloud-dn.ospserver.net/firmware/" + region + "/" + model + "/version.xml");
38 | string str2;
39 | if (latest == true)
40 | {
41 | str2 = Xml.GetXMLValue(xml, "firmware/version/latest", null, null).ToUpper();
42 | }
43 | else
44 | {
45 | str2 = Xml.GetXMLValue(xml, "firmware/version/upgrade/value", null, null).ToUpper();
46 | }
47 | return str2;
48 | }
49 | }
50 | catch (Exception)
51 | {
52 | return string.Empty;
53 | }
54 | }
55 |
56 | public static string FOTAInfoFetch1(string model, string region) =>
57 | FOTAInfoFetch(model, region, true);
58 |
59 | public static string FOTAInfoFetch2(string model, string region) =>
60 | FOTAInfoFetch(model, region, false);
61 |
62 | private static string GetInfoSFO(string html, string search)
63 | {
64 | if (string.IsNullOrEmpty(html))
65 | {
66 | return string.Empty;
67 | }
68 | int index = html.IndexOf(">" + search + "<");
69 | if (index < 0)
70 | {
71 | return string.Empty;
72 | }
73 | index += (search.Length + 1) + 0x13;
74 | string str = html.Substring(index);
75 | return str.Substring(0, str.IndexOf('<'));
76 | }
77 |
78 | //http://www.sammobile.com
79 | public static string SamMobileFetch(string model, string region, int index)
80 | {
81 | string samMobileHtml = SamMobileHtml;
82 | if (string.IsNullOrEmpty(samMobileHtml))
83 | {
84 | return string.Empty;
85 | }
86 | if (samMobileHtml.Contains("Device model not found"))
87 | {
88 | return string.Empty;
89 | }
90 | int num = 0;
91 | while ((index-- >= 0) && (num >= 0))
92 | {
93 | num = samMobileHtml.IndexOf("
142 | SamMobileFetch(model, region, 1);
143 |
144 | //https://samsung-firmware.org
145 | public static string SamsungFirmwareOrgFetch(string model, string region)
146 | {
147 | string samsungFirmwareOrgHtml = SamsungFirmwareOrgHtml;
148 | int index = samsungFirmwareOrgHtml.IndexOf("\"/model/" + model + "/\"");
149 | if (index < 0)
150 | {
151 | return string.Empty;
152 | }
153 | samsungFirmwareOrgHtml = samsungFirmwareOrgHtml.Substring(index);
154 |
155 | StringBuilder bld = new StringBuilder();
156 | bld.Append("https://samsung-firmware.org");
157 |
158 | using (StringReader reader = new StringReader(samsungFirmwareOrgHtml))
159 | {
160 | string str3;
161 | while ((str3 = reader.ReadLine()) != null)
162 | {
163 | if (str3.Contains("Download"))
164 | {
165 | int num2 = str3.IndexOf('"');
166 | int length = str3.Substring(num2 + 1).IndexOf('"');
167 | bld.Append(str3.Substring(num2 + 1, length));
168 | break;
169 | }
170 | }
171 | }
172 |
173 | string url = bld.ToString();
174 | samsungFirmwareOrgHtml = Utility.GetHtml(url);
175 | string infoSFO = GetInfoSFO(samsungFirmwareOrgHtml, "PDA Version");
176 | string str5 = GetInfoSFO(samsungFirmwareOrgHtml, "CSC Version");
177 | string str6 = GetInfoSFO(samsungFirmwareOrgHtml, "PHONE Version");
178 | if ((string.IsNullOrEmpty(infoSFO) || string.IsNullOrEmpty(str5)) || string.IsNullOrEmpty(str6))
179 | {
180 | return string.Empty;
181 | }
182 | return (infoSFO + "/" + str5 + "/" + str6);
183 | }
184 |
185 | public static string SamsungFirmwareOrgFetch1(string model, string region)
186 | {
187 | SamsungFirmwareOrgHtml = Utility.GetHtml("https://samsung-firmware.org/model/" + model + "/region/" + region + "/");
188 | return SamsungFirmwareOrgFetch(model, region);
189 | }
190 |
191 | public static string SamsungFirmwareOrgFetch2(string model, string region)
192 | {
193 | string str = SamsungFirmwareOrgFetch(model, region);
194 | if (!string.IsNullOrEmpty(str))
195 | {
196 | string[] strArray = str.Split(new [] { '/' });
197 | str = strArray[0] + "/" + strArray[2] + "/" + strArray[1];
198 | }
199 | return str;
200 | }
201 |
202 | //http://samsung-updates.com (연결안됨)
203 | private static string SamsungUpdatesFetch(string model, string region)
204 | {
205 | try
206 | {
207 | using (WebClient client = new WebClient())
208 | {
209 | string s = client.DownloadString("http://samsung-updates.com/device/?id=" + model);
210 | StringBuilder bld = new StringBuilder();
211 | bld.Append("http://samsung-updates.com");
212 | bool flag = false;
213 | using (StringReader reader = new StringReader(s))
214 | {
215 | string str3;
216 | while ((str3 = reader.ReadLine()) != null)
217 | {
218 | if (str3.Contains("/" + model + "/" + region + "/"))
219 | {
220 | int index = str3.IndexOf("a href=\"");
221 | int length = str3.Substring(index + 8).IndexOf('"');
222 | bld.Append(str3.Substring(index + 8, length));
223 | flag = true;
224 | break;
225 | }
226 | }
227 | }
228 |
229 | if (!flag)
230 | {
231 | return string.Empty;
232 | }
233 | string address = bld.ToString();
234 | s = client.DownloadString(address);
235 | Match match = Regex.Match(s, @"PDA: ([^\s]+) ");
236 | if (!match.Success)
237 | {
238 | return string.Empty;
239 | }
240 | string format = match.Groups[1].Value + "/{0}/" + match.Groups[1].Value;
241 | match = Regex.Match(s, @"CSC: ([^\s]+) ");
242 | if (!match.Success)
243 | {
244 | return string.Empty;
245 | }
246 | return string.Format(format, match.Groups[1].Value);
247 | }
248 | }
249 | catch (WebException)
250 | {
251 | return string.Empty;
252 | }
253 | }
254 |
255 | private static string tdExtract(string line)
256 | {
257 | int startIndex = line.IndexOf("") + 4;
258 | int index = line.IndexOf(" | ");
259 | if ((startIndex >= 0) && (index >= 0))
260 | {
261 | return line.Substring(startIndex, index - startIndex);
262 | }
263 | return string.Empty;
264 | }
265 | }
266 | }
--------------------------------------------------------------------------------
/SamFirm/Imports.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Reflection;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace SamFirm
7 | {
8 | internal class Imports
9 | {
10 | private static IntPtr mod = IntPtr.Zero;
11 |
12 | //콘솔을 메모리에서 반환하는 메소드
13 | [DllImport("kernel32.dll")]
14 | public static extern bool FreeConsole();
15 |
16 | //모듈(라이브러리)을 메모리에서 반환하는 메소드
17 | [DllImport("kernel32.dll")]
18 | private static extern bool FreeLibrary(IntPtr hModule);
19 | public static void FreeModule()
20 | {
21 | if (mod != IntPtr.Zero)
22 | {
23 | if (!FreeLibrary(mod))
24 | {
25 | Logger.WriteLine("Error FreeModule(): Unable to free library.");
26 | }
27 | mod = IntPtr.Zero;
28 | }
29 | }
30 |
31 | //권한을 얻는 메소드
32 | public static string GetAuthorization(string Nonce)
33 | {
34 | if ((mod == IntPtr.Zero) && (LoadModule("AgentModule.dll") != 0))
35 | {
36 | return string.Empty;
37 | }
38 | Auth_t _t = load_function(mod, "?MakeAuthorizationHeaderWithGeneratedNonceValueAndAMModule@AgentNetworkModule@@CAPB_WPB_W@Z");
39 | IntPtr nonce = Marshal.StringToHGlobalUni(Nonce);
40 | string str = Marshal.PtrToStringUni(_t(nonce));
41 | Marshal.FreeHGlobal(nonce);
42 | return str;
43 | }
44 |
45 | [DllImport("kernel32.dll")]
46 | private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
47 | private static T load_function(IntPtr module, string name) where T: class =>
48 | (Marshal.GetDelegateForFunctionPointer(GetProcAddress(module, name), typeof(T)) as T);
49 |
50 | //모듈(라이브러리)을 로드하는 메소드
51 | [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
52 | private static extern IntPtr LoadLibrary(string dllToLoad);
53 | private static int LoadModule(string module)
54 | {
55 | try
56 | {
57 | string modulePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
58 | modulePath = Path.Combine(modulePath, "DLL", module);
59 | if (!File.Exists(modulePath))
60 | {
61 | Logger.WriteLine("Error LoadModule(): " + module + " does not exist.");
62 | return 1;
63 | }
64 |
65 | mod = LoadLibrary(modulePath);
66 | if (mod == IntPtr.Zero)
67 | {
68 | Logger.WriteLine("Error LoadLibrary(): " + Marshal.GetLastWin32Error().ToString());
69 | Logger.WriteLine("Please make sure \"Microsoft Visual C++ 2008 Redistributable Package (x86)\" and \"Microsoft Visual C++ 2010 Redistributable Package (x86)\" are installed.");
70 | return 1;
71 | }
72 | }
73 | catch (Exception exception)
74 | {
75 | Logger.WriteLine("Error LoadModule() -> " + exception);
76 | return 1;
77 | }
78 | return 0;
79 | }
80 |
81 | //스레드 실행 상태를 설정하는 메소드
82 | [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
83 | public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
84 |
85 | [UnmanagedFunctionPointer(CallingConvention.Winapi)]
86 | private delegate IntPtr Auth_t(IntPtr nonce);
87 |
88 | public enum EXECUTION_STATE : uint
89 | {
90 | ES_AWAYMODE_REQUIRED = 0x40,
91 | ES_CONTINUOUS = 0x80000000,
92 | ES_DISPLAY_REQUIRED = 2,
93 | ES_SYSTEM_REQUIRED = 1
94 | }
95 | }
96 | }
--------------------------------------------------------------------------------
/SamFirm/KiesRequest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 |
4 | namespace SamFirm
5 | {
6 | internal class KiesRequest : WebRequest
7 | {
8 | public static new HttpWebRequest Create(string requestUriString)
9 | {
10 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString);
11 | request.Headers["Cache-Control"] = "no-cache";
12 | request.UserAgent = "Kies2.0_FUS";
13 | request.Headers.Add("Authorization", "FUS nonce=\"\", signature=\"\", nc=\"\", type=\"\", realm=\"\"");
14 | CookieContainer container = new CookieContainer(1);
15 | Cookie cookie = new Cookie("JSESSIONID", Web.JSessionID);
16 | container.Add(new Uri(requestUriString), cookie);
17 | request.CookieContainer = container;
18 | return request;
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/SamFirm/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Windows.Forms;
4 |
5 | namespace SamFirm
6 | {
7 | internal static class Logger
8 | {
9 | public static MainForm Form { get; set; }
10 |
11 | //현재 날짜와 시각을 알아내는 함수
12 | private static string GetTimeDate()
13 | {
14 | return DateTime.Now.ToString("yyyy/MM/dd") + " " + DateTime.Now.ToString("HH:mm:ss");
15 | }
16 |
17 | //로그를 파일로 저장하는 메소드
18 | public static void SaveLog()
19 | {
20 | if (!string.IsNullOrEmpty(Form.Log_textbox.Text))
21 | {
22 | using (TextWriter writer = new StreamWriter(new FileStream("SamFirm.log", FileMode.Create)))
23 | {
24 | writer.WriteLine(GetTimeDate());
25 | foreach (string str in Form.Log_textbox.Lines)
26 | {
27 | writer.WriteLine(str);
28 | }
29 | }
30 | }
31 | }
32 |
33 | //로그 텍스트 박스에 문자열을 출력하는 메소드
34 | public static void WriteLine(string str)
35 | {
36 | if (Form.Log_textbox.InvokeRequired)
37 | {
38 | Form.Log_textbox.Invoke(new Action(() =>
39 | {
40 | Form.Log_textbox.AppendText(str + "\n");
41 | Form.Log_textbox.ScrollToCaret();
42 | }));
43 | }
44 | else
45 | {
46 | Form.Log_textbox.AppendText(str + "\n");
47 | Form.Log_textbox.ScrollToCaret();
48 | }
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/SamFirm/MainForm.Designer.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 |
3 | namespace SamFirm
4 | {
5 | partial class MainForm
6 | {
7 | ///
8 | /// 필수 디자이너 변수입니다.
9 | ///
10 | private System.ComponentModel.IContainer components = null;
11 |
12 | ///
13 | /// 사용 중인 모든 리소스를 정리합니다.
14 | ///
15 | /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.
16 | protected override void Dispose(bool disposing)
17 | {
18 | if (disposing && (components != null))
19 | {
20 | components.Dispose();
21 | }
22 | base.Dispose(disposing);
23 | }
24 |
25 | #region Windows Form 디자이너에서 생성한 코드
26 |
27 | ///
28 | /// 디자이너 지원에 필요한 메서드입니다.
29 | /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
30 | ///
31 | private void InitializeComponent()
32 | {
33 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
34 | this.groupBox1 = new System.Windows.Forms.GroupBox();
35 | this.size_label = new System.Windows.Forms.Label();
36 | this.update_button = new System.Windows.Forms.Button();
37 | this.binary_checkbox = new System.Windows.Forms.CheckBox();
38 | this.label8 = new System.Windows.Forms.Label();
39 | this.speed_label = new System.Windows.Forms.Label();
40 | this.region_textbox = new System.Windows.Forms.TextBox();
41 | this.model_textbox = new System.Windows.Forms.TextBox();
42 | this.label9 = new System.Windows.Forms.Label();
43 | this.label2 = new System.Windows.Forms.Label();
44 | this.label1 = new System.Windows.Forms.Label();
45 | this.groupBox2 = new System.Windows.Forms.GroupBox();
46 | this.progressBar1 = new System.Windows.Forms.ProgressBar();
47 | this.decrypt_button = new System.Windows.Forms.Button();
48 | this.download_button = new System.Windows.Forms.Button();
49 | this.autoDecrypt_checkbox = new System.Windows.Forms.CheckBox();
50 | this.version_textbox = new System.Windows.Forms.TextBox();
51 | this.file_textbox = new System.Windows.Forms.TextBox();
52 | this.label7 = new System.Windows.Forms.Label();
53 | this.label6 = new System.Windows.Forms.Label();
54 | this.log_textbox = new System.Windows.Forms.RichTextBox();
55 | this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
56 | this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
57 | this.groupBox1.SuspendLayout();
58 | this.groupBox2.SuspendLayout();
59 | this.SuspendLayout();
60 | //
61 | // groupBox1
62 | //
63 | this.groupBox1.Controls.Add(this.size_label);
64 | this.groupBox1.Controls.Add(this.update_button);
65 | this.groupBox1.Controls.Add(this.binary_checkbox);
66 | this.groupBox1.Controls.Add(this.label8);
67 | this.groupBox1.Controls.Add(this.speed_label);
68 | this.groupBox1.Controls.Add(this.region_textbox);
69 | this.groupBox1.Controls.Add(this.model_textbox);
70 | this.groupBox1.Controls.Add(this.label9);
71 | this.groupBox1.Controls.Add(this.label2);
72 | this.groupBox1.Controls.Add(this.label1);
73 | resources.ApplyResources(this.groupBox1, "groupBox1");
74 | this.groupBox1.Name = "groupBox1";
75 | this.groupBox1.TabStop = false;
76 | //
77 | // size_label
78 | //
79 | resources.ApplyResources(this.size_label, "size_label");
80 | this.size_label.Name = "size_label";
81 | //
82 | // update_button
83 | //
84 | resources.ApplyResources(this.update_button, "update_button");
85 | this.update_button.Name = "update_button";
86 | this.update_button.UseVisualStyleBackColor = true;
87 | this.update_button.Click += new System.EventHandler(this.Update_button_Click);
88 | //
89 | // binary_checkbox
90 | //
91 | resources.ApplyResources(this.binary_checkbox, "binary_checkbox");
92 | this.binary_checkbox.Name = "binary_checkbox";
93 | this.binary_checkbox.UseVisualStyleBackColor = true;
94 | //
95 | // label8
96 | //
97 | resources.ApplyResources(this.label8, "label8");
98 | this.label8.Name = "label8";
99 | //
100 | // speed_label
101 | //
102 | resources.ApplyResources(this.speed_label, "speed_label");
103 | this.speed_label.Name = "speed_label";
104 | //
105 | // region_textbox
106 | //
107 | this.region_textbox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
108 | resources.ApplyResources(this.region_textbox, "region_textbox");
109 | this.region_textbox.Name = "region_textbox";
110 | //
111 | // model_textbox
112 | //
113 | this.model_textbox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
114 | resources.ApplyResources(this.model_textbox, "model_textbox");
115 | this.model_textbox.Name = "model_textbox";
116 | //
117 | // label9
118 | //
119 | resources.ApplyResources(this.label9, "label9");
120 | this.label9.Name = "label9";
121 | //
122 | // label2
123 | //
124 | resources.ApplyResources(this.label2, "label2");
125 | this.label2.Name = "label2";
126 | //
127 | // label1
128 | //
129 | resources.ApplyResources(this.label1, "label1");
130 | this.label1.Name = "label1";
131 | //
132 | // groupBox2
133 | //
134 | resources.ApplyResources(this.groupBox2, "groupBox2");
135 | this.groupBox2.Controls.Add(this.progressBar1);
136 | this.groupBox2.Controls.Add(this.decrypt_button);
137 | this.groupBox2.Controls.Add(this.download_button);
138 | this.groupBox2.Controls.Add(this.autoDecrypt_checkbox);
139 | this.groupBox2.Controls.Add(this.version_textbox);
140 | this.groupBox2.Controls.Add(this.file_textbox);
141 | this.groupBox2.Controls.Add(this.label7);
142 | this.groupBox2.Controls.Add(this.label6);
143 | this.groupBox2.Name = "groupBox2";
144 | this.groupBox2.TabStop = false;
145 | //
146 | // progressBar1
147 | //
148 | resources.ApplyResources(this.progressBar1, "progressBar1");
149 | this.progressBar1.Name = "progressBar1";
150 | //
151 | // decrypt_button
152 | //
153 | resources.ApplyResources(this.decrypt_button, "decrypt_button");
154 | this.decrypt_button.Name = "decrypt_button";
155 | this.decrypt_button.UseVisualStyleBackColor = true;
156 | this.decrypt_button.Click += new System.EventHandler(this.Decrypt_button_Click);
157 | //
158 | // download_button
159 | //
160 | resources.ApplyResources(this.download_button, "download_button");
161 | this.download_button.Name = "download_button";
162 | this.download_button.UseVisualStyleBackColor = true;
163 | this.download_button.Click += new System.EventHandler(this.Download_button_Click);
164 | //
165 | // autoDecrypt_checkbox
166 | //
167 | resources.ApplyResources(this.autoDecrypt_checkbox, "autoDecrypt_checkbox");
168 | this.autoDecrypt_checkbox.Checked = true;
169 | this.autoDecrypt_checkbox.CheckState = System.Windows.Forms.CheckState.Checked;
170 | this.autoDecrypt_checkbox.Name = "autoDecrypt_checkbox";
171 | this.autoDecrypt_checkbox.UseVisualStyleBackColor = true;
172 | //
173 | // version_textbox
174 | //
175 | resources.ApplyResources(this.version_textbox, "version_textbox");
176 | this.version_textbox.Name = "version_textbox";
177 | this.version_textbox.ReadOnly = true;
178 | this.version_textbox.TabStop = false;
179 | //
180 | // file_textbox
181 | //
182 | resources.ApplyResources(this.file_textbox, "file_textbox");
183 | this.file_textbox.Name = "file_textbox";
184 | this.file_textbox.ReadOnly = true;
185 | this.file_textbox.TabStop = false;
186 | //
187 | // label7
188 | //
189 | resources.ApplyResources(this.label7, "label7");
190 | this.label7.Name = "label7";
191 | //
192 | // label6
193 | //
194 | resources.ApplyResources(this.label6, "label6");
195 | this.label6.Name = "label6";
196 | //
197 | // log_textbox
198 | //
199 | resources.ApplyResources(this.log_textbox, "log_textbox");
200 | this.log_textbox.Name = "log_textbox";
201 | this.log_textbox.ReadOnly = true;
202 | this.log_textbox.TabStop = false;
203 | //
204 | // saveFileDialog1
205 | //
206 | this.saveFileDialog1.AddExtension = false;
207 | resources.ApplyResources(this.saveFileDialog1, "saveFileDialog1");
208 | this.saveFileDialog1.OverwritePrompt = false;
209 | this.saveFileDialog1.SupportMultiDottedExtensions = true;
210 | //
211 | // openFileDialog1
212 | //
213 | resources.ApplyResources(this.openFileDialog1, "openFileDialog1");
214 | this.openFileDialog1.SupportMultiDottedExtensions = true;
215 | //
216 | // MainForm
217 | //
218 | this.AcceptButton = this.update_button;
219 | resources.ApplyResources(this, "$this");
220 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
221 | this.Controls.Add(this.log_textbox);
222 | this.Controls.Add(this.groupBox2);
223 | this.Controls.Add(this.groupBox1);
224 | this.MaximizeBox = false;
225 | this.Name = "MainForm";
226 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
227 | this.Load += new System.EventHandler(this.MainForm_Load);
228 | this.groupBox1.ResumeLayout(false);
229 | this.groupBox1.PerformLayout();
230 | this.groupBox2.ResumeLayout(false);
231 | this.groupBox2.PerformLayout();
232 | this.ResumeLayout(false);
233 |
234 | }
235 |
236 | #endregion
237 |
238 | //필드 (컨트롤)
239 | private System.Windows.Forms.Button update_button;
240 | private System.Windows.Forms.Button download_button;
241 | private System.Windows.Forms.Button decrypt_button;
242 | private System.Windows.Forms.CheckBox binary_checkbox;
243 | private System.Windows.Forms.CheckBox autoDecrypt_checkbox;
244 | private System.Windows.Forms.GroupBox groupBox1;
245 | private System.Windows.Forms.GroupBox groupBox2;
246 | private System.Windows.Forms.Label label1;
247 | private System.Windows.Forms.Label label2;
248 | private System.Windows.Forms.Label label6;
249 | private System.Windows.Forms.Label label7;
250 | private System.Windows.Forms.Label label8;
251 | private System.Windows.Forms.Label label9;
252 | private System.Windows.Forms.Label size_label;
253 | private System.Windows.Forms.Label speed_label;
254 | private System.Windows.Forms.OpenFileDialog openFileDialog1;
255 | private System.Windows.Forms.ProgressBar progressBar1;
256 | private System.Windows.Forms.RichTextBox log_textbox;
257 | private System.Windows.Forms.SaveFileDialog saveFileDialog1;
258 | private System.Windows.Forms.TextBox model_textbox;
259 | private System.Windows.Forms.TextBox region_textbox;
260 | private System.Windows.Forms.TextBox file_textbox;
261 | private System.Windows.Forms.TextBox version_textbox;
262 |
263 | //Getter, Setter 메소드
264 | public RichTextBox Log_textbox { get => log_textbox; set => log_textbox = value; }
265 | public Label Speed_label { get => speed_label; set => speed_label = value; }
266 | }
267 | }
--------------------------------------------------------------------------------
/SamFirm/MainForm.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.WindowsAPICodePack.Taskbar;
2 | using System;
3 | using System.ComponentModel;
4 | using System.Diagnostics;
5 | using System.Globalization;
6 | using System.IO;
7 | using System.Net;
8 | using System.Reflection;
9 | using System.Windows.Forms;
10 |
11 | namespace SamFirm
12 | {
13 | internal partial class MainForm : Form
14 | {
15 | private string destinationFile; //다운로드하는 파일의 경로와 이름을 저장한다.
16 | private Command.Firmware FW; //다운로드할 펌웨어의 정보를 저장하는 구조체 객체.
17 | public bool PauseDownload { get; set; } //다운로드가 일시정지 되었는지 여부를 저장한다.
18 |
19 |
20 | //생성자
21 | public MainForm()
22 | {
23 | InitializeComponent();
24 | }
25 |
26 | //폼을 로드하면 호출하는 메소드
27 | private void MainForm_Load(object sender, EventArgs e)
28 | {
29 | //각 클래스의 form필드에 이 클래스를 붙여준다.
30 | Logger.Form = this;
31 | Web.Form = this;
32 | Decrypt.Form = this;
33 |
34 | //각 컨트롤에 설정파일에서 불러온 값을 적용한다.
35 | model_textbox.Text = Settings.ReadSetting("Model");
36 | region_textbox.Text = Settings.ReadSetting("Region");
37 | binary_checkbox.Checked = bool.Parse(Settings.ReadSetting("BinaryNature"));
38 | autoDecrypt_checkbox.Checked = bool.Parse(Settings.ReadSetting("AutoDecrypt"));
39 |
40 | //버전정보를 출력한다.
41 | FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
42 | Logger.WriteLine("SamFirm v" + versionInfo.FileVersion);
43 |
44 |
45 | //서버 인증서의 유효성을 검사하는 콜백을 설정한다.
46 | ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => true;
47 |
48 | //다운로드 버튼, 복호화 버튼 비활성화
49 | download_button.Enabled = false;
50 | decrypt_button.Enabled = false;
51 | }
52 |
53 | //폼을 닫으면 호출하는 메소드
54 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
55 | {
56 | //설정값을 저장한다.
57 | Settings.SetSetting("Model", model_textbox.Text);
58 | Settings.SetSetting("Region", region_textbox.Text);
59 | Settings.SetSetting("BinaryNature", binary_checkbox.Checked.ToString());
60 | Settings.SetSetting("AutoDecrypt", autoDecrypt_checkbox.Checked.ToString());
61 |
62 | //다운로드 일시정지 필드를 true로 한다.
63 | PauseDownload = true;
64 |
65 | //모듈을 메모리에서 내리고, 로그를 파일로 저장한다.
66 | Imports.FreeModule();
67 | Logger.SaveLog();
68 | }
69 |
70 | //Update 버튼 클릭시 실행하는 메소드
71 | private void Update_button_Click(object sender, EventArgs e)
72 | {
73 | //예외 처리
74 | if (string.IsNullOrEmpty(model_textbox.Text) || string.IsNullOrEmpty(region_textbox.Text))
75 | {
76 | Logger.WriteLine("Error: Please specify a model or a region.");
77 | return;
78 | }
79 |
80 | //백그라운드 작업 등록
81 | using (BackgroundWorker worker = new BackgroundWorker())
82 | {
83 | worker.DoWork += delegate
84 | {
85 | try
86 | {
87 | SetProgressBar(0);
88 | ControlsEnabled(false);
89 | Utility.ReconnectDownload = false;
90 |
91 | //업데이트를 검사한다.
92 | FW = Command.UpdateCheckAuto(model_textbox.Text, region_textbox.Text, binary_checkbox.Checked);
93 |
94 | //FW 구조체의 Filename멤버가 비어있으면 빈 글자를 출력하고,
95 | //비어있지 않으면 FW의 멤버를 출력한다.
96 | if (string.IsNullOrEmpty(FW.Filename))
97 | {
98 | file_textbox.Invoke(new Action(() => file_textbox.Text = string.Empty));
99 | version_textbox.Invoke(new Action(() => version_textbox.Text = string.Empty));
100 | size_label.Invoke(new Action(() => size_label.Text = "0 GB"));
101 | }
102 | else
103 | {
104 | file_textbox.Invoke(new Action(() => file_textbox.Text = FW.Filename));
105 | version_textbox.Invoke(new Action(() => version_textbox.Text = FW.Version));
106 | double size = Math.Round(long.Parse(FW.Size) / 1024.0 / 1024.0 / 1024.0, 3);
107 | size_label.Invoke(new Action(() => size_label.Text = size.ToString(CultureInfo.InvariantCulture) + " GB"));
108 | }
109 |
110 | //출력을 완료하면 컨트롤을 활성화한다.
111 | ControlsEnabled(true);
112 | }
113 | catch (Exception exception)
114 | {
115 | Logger.WriteLine("Error Update_button_Click() -> " + exception);
116 | }
117 | };
118 | worker.RunWorkerAsync();
119 | }
120 | }
121 |
122 | //Download 버튼 클릭시 실행하는 메소드
123 | private void Download_button_Click(object sender, EventArgs e)
124 | {
125 | //다운로드를 일시정지한다.
126 | if (download_button.Text == "Pause")
127 | {
128 | Utility.TaskBarProgressPaused(true);
129 | PauseDownload = true;
130 | Utility.ReconnectDownload = false;
131 | download_button.Text = "Download";
132 | return;
133 | }
134 |
135 | //예외 처리
136 | if ((e.GetType() == typeof(DownloadEventArgs)) && ((DownloadEventArgs)e).isReconnect)
137 | {
138 | if (download_button.Text == "Pause" || !Utility.ReconnectDownload)
139 | {
140 | return;
141 | }
142 | }
143 | if (PauseDownload == true)
144 | {
145 | Logger.WriteLine("Download thread is still running. Please wait.");
146 | return;
147 | }
148 | else if (string.IsNullOrEmpty(FW.Filename))
149 | {
150 | Logger.WriteLine("No file to download. Please check for update first.");
151 | return;
152 | }
153 |
154 | //다운로드 작업
155 | if ((e.GetType() != typeof(DownloadEventArgs)) || !((DownloadEventArgs)e).isReconnect)
156 | {
157 | //extension = .zip.enc4
158 | string extension = Path.GetExtension(Path.GetFileNameWithoutExtension(FW.Filename)) + Path.GetExtension(FW.Filename);
159 |
160 | //파일이름의 기본값을 Model_Region_LastModified_Version으로 한다.
161 | string filename = string.Join("_", new string[] { FW.Model, FW.LastModified.Substring(0, 8), FW.Region, FW.Version.Replace('/', '-') });
162 | saveFileDialog1.FileName = filename + extension;
163 |
164 | //확인 버튼을 누르지 않으면 다운로드를 취소한다.
165 | if (saveFileDialog1.ShowDialog() != DialogResult.OK)
166 | {
167 | Logger.WriteLine("Download canceled.");
168 | return;
169 | }
170 |
171 | //확장자가 .zip.enc4로 끝나지 않으면 따로 붙여준다.
172 | if (saveFileDialog1.FileName.EndsWith(extension) != true)
173 | {
174 | destinationFile = saveFileDialog1.FileName + extension;
175 | }
176 | else
177 | {
178 | destinationFile = saveFileDialog1.FileName;
179 | }
180 |
181 | //파일명을 출력한다.
182 | Logger.WriteLine("\nFilename: " + FW.Filename);
183 |
184 | //목적지에 파일이 존재하면 대화상자를 보여준다.
185 | if (File.Exists(destinationFile))
186 | {
187 | using (AppendDialogBox appendDialog = new AppendDialogBox())
188 | {
189 | switch (appendDialog.ShowDialog())
190 | {
191 | case DialogResult.Yes: //append
192 | break;
193 |
194 | case DialogResult.No: //overwrite
195 | File.Delete(destinationFile);
196 | break;
197 |
198 | case DialogResult.Cancel:
199 | Logger.WriteLine("Download canceled.");
200 | return;
201 |
202 | default:
203 | Logger.WriteLine("Error: Wrong DialogResult.");
204 | return;
205 | }
206 | }
207 | }
208 | }
209 |
210 | //백그라운드 작업 등록
211 | Utility.TaskBarProgressPaused(false);
212 | using (BackgroundWorker worker = new BackgroundWorker())
213 | {
214 | worker.DoWork += delegate (object o, DoWorkEventArgs _e)
215 | {
216 | try
217 | {
218 | ControlsEnabled(false);
219 | Utility.ReconnectDownload = false;
220 |
221 | //다운로드 버튼을 일시정지 버튼으로 바꾼다.
222 | MethodInvoker invoker1 = delegate
223 | {
224 | download_button.Enabled = true;
225 | download_button.Text = "Pause";
226 | };
227 | download_button.Invoke(invoker1);
228 |
229 | //다운로드 경로와 파일명을 출력한다.
230 | Logger.WriteLine("Download: " + destinationFile);
231 |
232 | //펌웨어 다운로드를 시작한다.
233 | Command.Download(FW.Path, FW.Filename, FW.Version, FW.Region, FW.Model_Type, destinationFile, FW.Size);
234 | if (PauseDownload == true)
235 | {
236 | Logger.WriteLine("Download paused.");
237 | PauseDownload = false;
238 | if (Utility.ReconnectDownload)
239 | {
240 | Logger.WriteLine("Reconnecting...");
241 | Utility.Reconnect(new Action