Skip to content

Commit

Permalink
GitHub desktop get away
Browse files Browse the repository at this point in the history
  • Loading branch information
veselcraft committed Oct 11, 2018
1 parent b8300a8 commit e019312
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 87 deletions.
141 changes: 58 additions & 83 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@
using System.Threading;
using System.Net;
using System.Diagnostics;
using Newtonsoft.Json;
using System.Resources;
using System.Reflection;

namespace VeNote
{
public partial class Form1 : RibbonForm
{
INIManager inimanager = new INIManager(Directory.GetCurrentDirectory() + "\\settings.ini");
static string exeasmb = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
INIManager inimanager = new INIManager(exeasmb + "\\settings.ini");
string[] arg;
string SaveDocumentQuestionString;
string UpdateMessageString;
string WordNotFoundString;
string[] originaltextstr;
public Form1(string[] args)
{
switch (inimanager.GetPrivateString("main", "language"))
{
case "en-US":
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

break;
case "ru-RU":
Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
Expand All @@ -42,28 +47,42 @@ public Form1(string[] args)
Thread.CurrentThread.CurrentCulture = new CultureInfo("be-BY");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("be-BY");
break;
case "ja-JP":
Thread.CurrentThread.CurrentCulture = new CultureInfo("ja-JP");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ja-JP");
break;

}

Assembly a = Assembly.Load("VeNote");
ResourceManager rm = new ResourceManager("VeNote.Form1", a);
SaveDocumentQuestionString = rm.GetString("SaveDocumentQuestionString");
UpdateMessageString = rm.GetString("UpdateMessageString");
WordNotFoundString = rm.GetString("WordNotFoundString");
InitializeComponent();
arg = args;
}

public static string GetUpdate()
{
string version = Application.ProductVersion;
string url = "http://veselcraft.ru/api/CheckUpdates.php?product=" + Application.ProductName;
string url = "http://veselcraft.ru/checkUpdates.php?product=" + Application.ProductName;
string versionActually;

using (var webCheckUpdate = new WebClient())
{
webCheckUpdate.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; VeNote " + Application.ProductVersion + ")");
Stream data = webCheckUpdate.OpenRead(url);
StreamReader reader = new StreamReader(data);
versionActually = reader.ReadToEnd();
}
return versionActually;
}

private void OriginalText() // Костыль, чтобы можно было выйти из программы, если только что открытый текст никак не изменялся
{
originaltextstr = richTextBoxClient.Lines;
}

private void Form1_Load(object sender, EventArgs e)
{
switch (inimanager.GetPrivateString("main", "style"))
Expand All @@ -83,6 +102,7 @@ private void Form1_Load(object sender, EventArgs e)
}
if (inimanager.GetPrivateString("main", "font") != null)
{

var cvt = new FontConverter();
Font f = cvt.ConvertFromString(inimanager.GetPrivateString("main", "font")) as Font;
richTextBoxClient.Font = f;
Expand All @@ -91,6 +111,7 @@ private void Form1_Load(object sender, EventArgs e)
{
richTextBoxClient.LoadFile(arg[0], RichTextBoxStreamType.PlainText);
this.Text = arg[0] + " - VeNote";
OriginalText();

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

}
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
{
case "en-US":
UpdateMessageString = "The update was released. Download?";
break;
case "uk-UA":
UpdateMessageString = "Вийшло оновлення. Завантажити?";
break;
case "ru-RU":
UpdateMessageString = "Вышло обновление. Скачать?";
break;
case "be-BY":
UpdateMessageString = "Выйшла абнаўленне. Скачать?";
break;
}

if (inimanager.GetPrivateString("main", "CheckUpdates") == "1")
{
if (GetUpdate() != "3.0.3.0")

string updateStr = GetUpdate();
UpdateJson updj = JsonConvert.DeserializeObject<UpdateJson>(updateStr);
if (updj.version != Application.ProductVersion)
{
if (MessageBox.Show(UpdateMessageString + " (" + GetUpdate() + ")", "VeNote", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (MessageBox.Show(UpdateMessageString + " (" + updj.version + ")", "VeNote", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Process.Start("http://veselcraft.ru/post.php?id=8");
Process.Start(updj.link);
}
}
}
Expand All @@ -150,7 +160,7 @@ private void Form1_Load(object sender, EventArgs e)

private void toolStripMenuItem1_Click(object sender, EventArgs e)
{

}

private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -159,12 +169,16 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBoxClient.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
this.Text = openFileDialog1.FileName;
OriginalText();
}
}

private void richTextBoxClient_TextChanged(object sender, EventArgs e)
{

if (this.Text.StartsWith("*") == false)
{
this.Text = "*" + this.Text;
}
}

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

private void ribbonButtonNew_Click(object sender, EventArgs e)
{
if (richTextBoxClient.Text != "")
if (richTextBoxClient.Text != "" || richTextBoxClient.Lines != originaltextstr)
{

switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
{
case "en-US":
SaveDocumentQuestionString = "Do you have to save this document?";
break;
case "uk-UA":
SaveDocumentQuestionString = "Ви хочете зберегти документ?";
break;
case "ru-RU":
SaveDocumentQuestionString = "Вы хотите сохранить документ?";
break;
case "be-BY":
SaveDocumentQuestionString = "Вы хочаце захаваць дакумент?";
break;
}
DialogResult SaveDocumentQuestion = MessageBox.Show(SaveDocumentQuestionString,
"VeNote",
MessageBoxButtons.YesNoCancel,
Expand All @@ -215,7 +213,7 @@ private void ribbonButtonNew_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
this.Text = "VeNote";
richTextBoxClient.Text = "";
}
Expand All @@ -234,6 +232,7 @@ private void ribbonButtonOpen_Click(object sender, EventArgs e)
{
richTextBoxClient.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
this.Text = openFileDialog1.FileName + " - VeNote";
OriginalText();
}
}

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

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
this.Text = saveFileDialog1.FileName + " - VeNote";
OriginalText();
}
}

private void ribbonButtonFont_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
richTextBoxClient.SelectionFont = fontDialog1.Font;
richTextBoxClient.Font = fontDialog1.Font;
var cvt = new FontConverter();
string fontSetting = cvt.ConvertToString(fontDialog1.Font);
inimanager.WritePrivateString("main", "font", fontSetting);
Expand All @@ -265,26 +265,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
inimanager.WritePrivateString("window", "locationy", Convert.ToString(this.Location.Y));
inimanager.WritePrivateString("window", "sizeh", Convert.ToString(this.Size.Height));
inimanager.WritePrivateString("window", "sizew", Convert.ToString(this.Size.Width));
if (richTextBoxClient.Text != "")
if (richTextBoxClient.Text != "" || richTextBoxClient.Lines == originaltextstr)
{
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
{
case "en-US":
SaveDocumentQuestionString = "Do you have to save this document?";
break;
case "uk-UA":
SaveDocumentQuestionString = "Ви хочете зберегти документ?";
break;
case "ru-RU":
SaveDocumentQuestionString = "Вы хотите сохранить документ?";
break;
case "be-BY":
SaveDocumentQuestionString = "Вы хочаце захаваць дакумент?";
break;
}



DialogResult SaveDocumentQuestion = MessageBox.Show(SaveDocumentQuestionString,
"VeNote",
MessageBoxButtons.YesNoCancel,
Expand All @@ -293,8 +275,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);

richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
Application.Exit();
}
}
else if (SaveDocumentQuestion == DialogResult.Cancel)
Expand Down Expand Up @@ -348,6 +330,7 @@ private void ribbonOrbMenuItemSettings_Click(object sender, EventArgs e)
ribbon1.OrbImage = null;
}
}
this.Activate();
}
}

Expand All @@ -357,23 +340,8 @@ private void ribbonOrbMenuItemExit_Click(object sender, EventArgs e)
inimanager.WritePrivateString("window", "locationy", Convert.ToString(this.Location.Y));
inimanager.WritePrivateString("window", "sizeh", Convert.ToString(this.Size.Height));
inimanager.WritePrivateString("window", "sizew", Convert.ToString(this.Size.Width));
if (richTextBoxClient.Text != "")
if (richTextBoxClient.Text != "" || richTextBoxClient.Lines != originaltextstr)
{
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
{
case "en-US":
SaveDocumentQuestionString = "Do you have to save this document?";
break;
case "uk-UA":
SaveDocumentQuestionString = "Ви хочете зберегти документ?";
break;
case "ru-RU":
SaveDocumentQuestionString = "Вы хотите сохранить документ?";
break;
case "be-BY":
SaveDocumentQuestionString = "Вы хочаце захаваць дакумент?";
break;
}
DialogResult SaveDocumentQuestion = MessageBox.Show(SaveDocumentQuestionString,
"VeNote",
MessageBoxButtons.YesNoCancel,
Expand All @@ -382,7 +350,7 @@ private void ribbonOrbMenuItemExit_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
richTextBoxClient.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.UnicodePlainText);
Application.Exit();
}
}
Expand Down Expand Up @@ -424,12 +392,19 @@ private void ribbonButtonFind_Click(object sender, EventArgs e)
}
if (findResult == -1)
{
MessageBox.Show("Слово не найдено");
MessageBox.Show(WordNotFoundString, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

}
}
}
}
}

class UpdateJson
{
public string version { get; set; }
public string link { get; set; }
}
}

8 changes: 4 additions & 4 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VeNote")]
[assembly: AssemblyDescription("Notepad clone written on C#")]
[assembly: AssemblyDescription("Simple notepad written on C#")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("veselcraft.ru")]
[assembly: AssemblyProduct("VeNote")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

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

0 comments on commit e019312

Please sign in to comment.