Skip to content

Commit e019312

Browse files
committed
GitHub desktop get away
1 parent b8300a8 commit e019312

File tree

2 files changed

+62
-87
lines changed

2 files changed

+62
-87
lines changed

Form1.cs

Lines changed: 58 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@
1212
using System.Threading;
1313
using System.Net;
1414
using System.Diagnostics;
15+
using Newtonsoft.Json;
16+
using System.Resources;
17+
using System.Reflection;
1518

1619
namespace VeNote
1720
{
1821
public partial class Form1 : RibbonForm
1922
{
20-
INIManager inimanager = new INIManager(Directory.GetCurrentDirectory() + "\\settings.ini");
23+
static string exeasmb = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
24+
INIManager inimanager = new INIManager(exeasmb + "\\settings.ini");
2125
string[] arg;
2226
string SaveDocumentQuestionString;
2327
string UpdateMessageString;
28+
string WordNotFoundString;
29+
string[] originaltextstr;
2430
public Form1(string[] args)
2531
{
2632
switch (inimanager.GetPrivateString("main", "language"))
2733
{
2834
case "en-US":
2935
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
3036
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
31-
3237
break;
3338
case "ru-RU":
3439
Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
@@ -42,28 +47,42 @@ public Form1(string[] args)
4247
Thread.CurrentThread.CurrentCulture = new CultureInfo("be-BY");
4348
Thread.CurrentThread.CurrentUICulture = new CultureInfo("be-BY");
4449
break;
50+
case "ja-JP":
51+
Thread.CurrentThread.CurrentCulture = new CultureInfo("ja-JP");
52+
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ja-JP");
53+
break;
4554

4655
}
47-
56+
Assembly a = Assembly.Load("VeNote");
57+
ResourceManager rm = new ResourceManager("VeNote.Form1", a);
58+
SaveDocumentQuestionString = rm.GetString("SaveDocumentQuestionString");
59+
UpdateMessageString = rm.GetString("UpdateMessageString");
60+
WordNotFoundString = rm.GetString("WordNotFoundString");
4861
InitializeComponent();
4962
arg = args;
5063
}
5164

5265
public static string GetUpdate()
5366
{
5467
string version = Application.ProductVersion;
55-
string url = "http://veselcraft.ru/api/CheckUpdates.php?product=" + Application.ProductName;
68+
string url = "http://veselcraft.ru/checkUpdates.php?product=" + Application.ProductName;
5669
string versionActually;
5770

5871
using (var webCheckUpdate = new WebClient())
5972
{
73+
webCheckUpdate.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; VeNote " + Application.ProductVersion + ")");
6074
Stream data = webCheckUpdate.OpenRead(url);
6175
StreamReader reader = new StreamReader(data);
6276
versionActually = reader.ReadToEnd();
6377
}
6478
return versionActually;
6579
}
6680

81+
private void OriginalText() // Костыль, чтобы можно было выйти из программы, если только что открытый текст никак не изменялся
82+
{
83+
originaltextstr = richTextBoxClient.Lines;
84+
}
85+
6786
private void Form1_Load(object sender, EventArgs e)
6887
{
6988
switch (inimanager.GetPrivateString("main", "style"))
@@ -83,6 +102,7 @@ private void Form1_Load(object sender, EventArgs e)
83102
}
84103
if (inimanager.GetPrivateString("main", "font") != null)
85104
{
105+
86106
var cvt = new FontConverter();
87107
Font f = cvt.ConvertFromString(inimanager.GetPrivateString("main", "font")) as Font;
88108
richTextBoxClient.Font = f;
@@ -91,6 +111,7 @@ private void Form1_Load(object sender, EventArgs e)
91111
{
92112
richTextBoxClient.LoadFile(arg[0], RichTextBoxStreamType.PlainText);
93113
this.Text = arg[0] + " - VeNote";
114+
OriginalText();
94115

95116
}
96117
if (inimanager.GetPrivateString("main", "wordwrap") == "0")
@@ -120,28 +141,17 @@ private void Form1_Load(object sender, EventArgs e)
120141
);
121142

122143
}
123-
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
124-
{
125-
case "en-US":
126-
UpdateMessageString = "The update was released. Download?";
127-
break;
128-
case "uk-UA":
129-
UpdateMessageString = "Вийшло оновлення. Завантажити?";
130-
break;
131-
case "ru-RU":
132-
UpdateMessageString = "Вышло обновление. Скачать?";
133-
break;
134-
case "be-BY":
135-
UpdateMessageString = "Выйшла абнаўленне. Скачать?";
136-
break;
137-
}
144+
138145
if (inimanager.GetPrivateString("main", "CheckUpdates") == "1")
139146
{
140-
if (GetUpdate() != "3.0.3.0")
147+
148+
string updateStr = GetUpdate();
149+
UpdateJson updj = JsonConvert.DeserializeObject<UpdateJson>(updateStr);
150+
if (updj.version != Application.ProductVersion)
141151
{
142-
if (MessageBox.Show(UpdateMessageString + " (" + GetUpdate() + ")", "VeNote", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
152+
if (MessageBox.Show(UpdateMessageString + " (" + updj.version + ")", "VeNote", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
143153
{
144-
Process.Start("http://veselcraft.ru/post.php?id=8");
154+
Process.Start(updj.link);
145155
}
146156
}
147157
}
@@ -150,7 +160,7 @@ private void Form1_Load(object sender, EventArgs e)
150160

151161
private void toolStripMenuItem1_Click(object sender, EventArgs e)
152162
{
153-
163+
154164
}
155165

156166
private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
@@ -159,12 +169,16 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
159169
{
160170
richTextBoxClient.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
161171
this.Text = openFileDialog1.FileName;
172+
OriginalText();
162173
}
163174
}
164175

165176
private void richTextBoxClient_TextChanged(object sender, EventArgs e)
166177
{
167-
178+
if (this.Text.StartsWith("*") == false)
179+
{
180+
this.Text = "*" + this.Text;
181+
}
168182
}
169183

170184
private void ribbonButtonPaste_Click(object sender, EventArgs e)
@@ -189,24 +203,8 @@ private void ribbonButtonSelectAll_Click(object sender, EventArgs e)
189203

190204
private void ribbonButtonNew_Click(object sender, EventArgs e)
191205
{
192-
if (richTextBoxClient.Text != "")
206+
if (richTextBoxClient.Text != "" || richTextBoxClient.Lines != originaltextstr)
193207
{
194-
195-
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
196-
{
197-
case "en-US":
198-
SaveDocumentQuestionString = "Do you have to save this document?";
199-
break;
200-
case "uk-UA":
201-
SaveDocumentQuestionString = "Ви хочете зберегти документ?";
202-
break;
203-
case "ru-RU":
204-
SaveDocumentQuestionString = "Вы хотите сохранить документ?";
205-
break;
206-
case "be-BY":
207-
SaveDocumentQuestionString = "Вы хочаце захаваць дакумент?";
208-
break;
209-
}
210208
DialogResult SaveDocumentQuestion = MessageBox.Show(SaveDocumentQuestionString,
211209
"VeNote",
212210
MessageBoxButtons.YesNoCancel,
@@ -215,7 +213,7 @@ private void ribbonButtonNew_Click(object sender, EventArgs e)
215213
{
216214
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
217215
{
218-
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
216+
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
219217
this.Text = "VeNote";
220218
richTextBoxClient.Text = "";
221219
}
@@ -234,6 +232,7 @@ private void ribbonButtonOpen_Click(object sender, EventArgs e)
234232
{
235233
richTextBoxClient.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
236234
this.Text = openFileDialog1.FileName + " - VeNote";
235+
OriginalText();
237236
}
238237
}
239238

@@ -242,16 +241,17 @@ private void ribbonButtonSave_Click(object sender, EventArgs e)
242241

243242
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
244243
{
245-
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
244+
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
246245
this.Text = saveFileDialog1.FileName + " - VeNote";
246+
OriginalText();
247247
}
248248
}
249249

250250
private void ribbonButtonFont_Click(object sender, EventArgs e)
251251
{
252252
if (fontDialog1.ShowDialog() == DialogResult.OK)
253253
{
254-
richTextBoxClient.SelectionFont = fontDialog1.Font;
254+
richTextBoxClient.Font = fontDialog1.Font;
255255
var cvt = new FontConverter();
256256
string fontSetting = cvt.ConvertToString(fontDialog1.Font);
257257
inimanager.WritePrivateString("main", "font", fontSetting);
@@ -265,26 +265,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
265265
inimanager.WritePrivateString("window", "locationy", Convert.ToString(this.Location.Y));
266266
inimanager.WritePrivateString("window", "sizeh", Convert.ToString(this.Size.Height));
267267
inimanager.WritePrivateString("window", "sizew", Convert.ToString(this.Size.Width));
268-
if (richTextBoxClient.Text != "")
268+
if (richTextBoxClient.Text != "" || richTextBoxClient.Lines == originaltextstr)
269269
{
270-
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
271-
{
272-
case "en-US":
273-
SaveDocumentQuestionString = "Do you have to save this document?";
274-
break;
275-
case "uk-UA":
276-
SaveDocumentQuestionString = "Ви хочете зберегти документ?";
277-
break;
278-
case "ru-RU":
279-
SaveDocumentQuestionString = "Вы хотите сохранить документ?";
280-
break;
281-
case "be-BY":
282-
SaveDocumentQuestionString = "Вы хочаце захаваць дакумент?";
283-
break;
284-
}
285-
286-
287-
288270
DialogResult SaveDocumentQuestion = MessageBox.Show(SaveDocumentQuestionString,
289271
"VeNote",
290272
MessageBoxButtons.YesNoCancel,
@@ -293,8 +275,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
293275
{
294276
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
295277
{
296-
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
297-
278+
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
279+
Application.Exit();
298280
}
299281
}
300282
else if (SaveDocumentQuestion == DialogResult.Cancel)
@@ -348,6 +330,7 @@ private void ribbonOrbMenuItemSettings_Click(object sender, EventArgs e)
348330
ribbon1.OrbImage = null;
349331
}
350332
}
333+
this.Activate();
351334
}
352335
}
353336

@@ -357,23 +340,8 @@ private void ribbonOrbMenuItemExit_Click(object sender, EventArgs e)
357340
inimanager.WritePrivateString("window", "locationy", Convert.ToString(this.Location.Y));
358341
inimanager.WritePrivateString("window", "sizeh", Convert.ToString(this.Size.Height));
359342
inimanager.WritePrivateString("window", "sizew", Convert.ToString(this.Size.Width));
360-
if (richTextBoxClient.Text != "")
343+
if (richTextBoxClient.Text != "" || richTextBoxClient.Lines != originaltextstr)
361344
{
362-
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
363-
{
364-
case "en-US":
365-
SaveDocumentQuestionString = "Do you have to save this document?";
366-
break;
367-
case "uk-UA":
368-
SaveDocumentQuestionString = "Ви хочете зберегти документ?";
369-
break;
370-
case "ru-RU":
371-
SaveDocumentQuestionString = "Вы хотите сохранить документ?";
372-
break;
373-
case "be-BY":
374-
SaveDocumentQuestionString = "Вы хочаце захаваць дакумент?";
375-
break;
376-
}
377345
DialogResult SaveDocumentQuestion = MessageBox.Show(SaveDocumentQuestionString,
378346
"VeNote",
379347
MessageBoxButtons.YesNoCancel,
@@ -382,7 +350,7 @@ private void ribbonOrbMenuItemExit_Click(object sender, EventArgs e)
382350
{
383351
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
384352
{
385-
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
353+
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
386354
Application.Exit();
387355
}
388356
}
@@ -424,12 +392,19 @@ private void ribbonButtonFind_Click(object sender, EventArgs e)
424392
}
425393
if (findResult == -1)
426394
{
427-
MessageBox.Show("Слово не найдено");
395+
MessageBox.Show(WordNotFoundString, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
428396
}
429397

430398
}
431399
}
432400
}
433401
}
434402
}
403+
404+
class UpdateJson
405+
{
406+
public string version { get; set; }
407+
public string link { get; set; }
408+
}
435409
}
410+

Properties/AssemblyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
88
[assembly: AssemblyTitle("VeNote")]
9-
[assembly: AssemblyDescription("Notepad clone written on C#")]
9+
[assembly: AssemblyDescription("Simple notepad written on C#")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("veselcraft.ru")]
1212
[assembly: AssemblyProduct("VeNote")]
13-
[assembly: AssemblyCopyright("Copyright © 2018")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.0.3.0")]
36-
[assembly: AssemblyFileVersion("3.0.3.0")]
35+
[assembly: AssemblyVersion("3.0.4.0")]
36+
[assembly: AssemblyFileVersion("3.0.4.0")]

0 commit comments

Comments
 (0)