Skip to content

Commit

Permalink
Updated GUI, Added Delete, Added sounds still play while in type mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam G authored and Liam G committed Mar 10, 2017
1 parent 7245534 commit a2742e9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 60 deletions.
136 changes: 76 additions & 60 deletions Chuuu/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Chuuu {

public partial class Form1 : Form {
public partial class Form1 :Form {

[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
Expand Down Expand Up @@ -64,7 +64,7 @@ public Form1() {

pictureBox1.AllowDrop = true;
CanPlaySound = true;
if (!Directory.Exists(@"Data\snd\")) {
if(!Directory.Exists(@"Data\snd\")) {
Directory.CreateDirectory(@"Data\snd\");
File.Create(@"Data\iwannadie.( ͡° ͜ʖ ͡°)");
}
Expand All @@ -78,14 +78,15 @@ public Form1() {
}

private void loadINI() {
if (File.Exists("Settings.ini") == false) {
if(File.Exists("Settings.ini") == false) {
var MyIni = new IniFile("Settings.ini");
MyIni.Write("KeyList", "https://ghostbin.com/paste/kkr4f", "Keys");
MyIni.Write("TypeModeKey", "Pause", "Keys");
MyIni.Write("TalkBackKey", "PageDown", "Keys");
TypeModeKey = MyIni.Read("TypeModeKey");
TalkBackKey = MyIni.Read("TalkBackKey");
} else {
}
else {
var MyIni = new IniFile("Settings.ini");
TypeModeKey = MyIni.Read("TypeModeKey", "Keys");
TalkBackKey = MyIni.Read("TalkBackKey", "Keys");
Expand All @@ -96,11 +97,11 @@ private void button1_Click(object sender, EventArgs e) {
}

private void unregKeys() {
if (File.Exists("chuuu.xml") == true) {
if(File.Exists("chuuu.xml") == true) {
XDocument doc = XDocument.Load("chuuu.xml");

if (new FileInfo("chuuu.xml").Length > 0) {
foreach (var coordinate in doc.Descendants("Key")) {
if(new FileInfo("chuuu.xml").Length > 0) {
foreach(var coordinate in doc.Descendants("Key")) {
string idString = coordinate.Element("ID").Value;

UnregisterHotKey(this.Handle, Convert.ToInt32(idString));
Expand All @@ -111,11 +112,11 @@ private void unregKeys() {

private void regKeys() {
listSnd.Items.Clear();
if (File.Exists("chuuu.xml") == true) {
if(File.Exists("chuuu.xml") == true) {
XDocument doc = XDocument.Load("chuuu.xml");

if (new FileInfo("chuuu.xml").Length > 0) {
foreach (var coordinate in doc.Descendants("Key")) {
if(new FileInfo("chuuu.xml").Length > 0) {
foreach(var coordinate in doc.Descendants("Key")) {
string idString = coordinate.Element("ID").Value;
string SoundFile = coordinate.Element("SoundFile").Value;
string KeyHot = coordinate.Element("KeyHot").Value;
Expand All @@ -131,18 +132,22 @@ private void regKeys() {
Keys keyMain;
Enum.TryParse(KeyHot, out keyMain);

if (KeyHotExtra == "Shift") {
if(KeyHotExtra == "Shift") {
RegisterHotKey(this.Handle, Convert.ToInt32(idString), (int)KeyModifier.Shift, (int)keyMain);
Console.Write("Shift");
}
if (KeyHotExtra == "Alt") {
if(KeyHotExtra == "Alt") {
RegisterHotKey(this.Handle, Convert.ToInt32(idString), (int)KeyModifier.Alt, (int)keyMain);
Console.Write("Alt");
}
if (KeyHotExtra == "Control") {
if(KeyHotExtra == "Control") {
RegisterHotKey(this.Handle, Convert.ToInt32(idString), (int)KeyModifier.Control, (int)keyMain);
Console.Write("Control");
}
if(KeyHotExtra == "None") {
RegisterHotKey(this.Handle, Convert.ToInt32(idString), (int)KeyModifier.None, (int)keyMain);
Console.Write("None");
}
Console.WriteLine((int)keyMain);

ListViewItem listSnd = new ListViewItem();
Expand All @@ -167,28 +172,30 @@ private void playSnd(string AudioSND) {
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
var sndArray = AudioList.ToArray();
if (CanPlaySound == true) {
if (m.Msg == WM_HOTKEY) {
if(CanPlaySound == true) {
if(m.Msg == WM_HOTKEY) {
Console.WriteLine(m.Msg);
//SendKeys.Send(m.HWnd);
if ((int)m.WParam == 9999) {
if (NotTyping == false) {
if((int)m.WParam == 9999) {
if(NotTyping == false) {
regKeys();
label1.Text = "Ready..";
NotTyping = true;
} else {
}
else {
unregKeys();
label1.Text = "Typing..";
NotTyping = false;
}
}

if (CanPlay == true && (int)m.WParam < 8000) {
if (NotTyping == true) {
if(CanPlay == true && (int)m.WParam < 8000) {
if(NotTyping == true) {
playSnd(sndArray[(int)m.WParam - 1]);
CanPlay = false;
}
} else if ((int)m.WParam != 9999) {
}
else if((int)m.WParam != 9999) {
SNDout.Stop();
CanPlay = true;
}
Expand All @@ -200,11 +207,11 @@ private void Form1_Load(object sender, EventArgs e) {
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
if (File.Exists("chuuu.xml") == true) {
if(File.Exists("chuuu.xml") == true) {
XDocument doc = XDocument.Load("chuuu.xml");

if (new FileInfo("chuuu.xml").Length > 0) {
foreach (var coordinate in doc.Descendants("Key")) {
if(new FileInfo("chuuu.xml").Length > 0) {
foreach(var coordinate in doc.Descendants("Key")) {
string idString = coordinate.Element("ID").Value;

UnregisterHotKey(this.Handle, Convert.ToInt32(idString));
Expand All @@ -221,7 +228,7 @@ private void xmlCreator() {
hkedit.StartPosition = FormStartPosition.CenterParent;
DialogResult dr = hkedit.ShowDialog(this);

if (dr == DialogResult.OK) {
if(dr == DialogResult.OK) {
hotKey_Main = hkedit.comboBox2.SelectedItem.ToString();
hotKey_Extra = hkedit.comboBox1.SelectedItem.ToString();
}
Expand All @@ -233,12 +240,12 @@ private void xmlCreator() {
var title = Regex.Replace(Path.GetFileNameWithoutExtension(audioFile), @"\s+", "");
string soundPath = @"data\snd\" + Path.GetFileName(audioFile);
soundPath = soundPath.Replace(@"\\", @"\");
if (File.Exists("chuuu.xml") == false) {
if(File.Exists("chuuu.xml") == false) {
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
xmlWriterSettings.NewLineOnAttributes = true;

using (XmlWriter xmlWriter = XmlWriter.Create("chuuu.xml", xmlWriterSettings)) {
using(XmlWriter xmlWriter = XmlWriter.Create("chuuu.xml", xmlWriterSettings)) {
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Chuuu");

Expand All @@ -254,7 +261,8 @@ private void xmlCreator() {
xmlWriter.Flush();
xmlWriter.Close();
}
} else {
}
else {
XDocument xDocument = XDocument.Load("chuuu.xml");
XElement root = xDocument.Element("Chuuu");
IEnumerable<XElement> rows = root.Descendants("Key");
Expand All @@ -276,10 +284,10 @@ private void button3_Click(object sender, EventArgs e) {

private static void WriteTop(string filename) {
string tempfile = Path.GetTempFileName();
using (var writer = new StreamWriter(tempfile))
using (var reader = new StreamReader(filename)) {
using(var writer = new StreamWriter(tempfile))
using(var reader = new StreamReader(filename)) {
writer.WriteLine("[");
while (!reader.EndOfStream)
while(!reader.EndOfStream)
writer.WriteLine(reader.ReadLine());
}
File.Copy(tempfile, filename, true);
Expand All @@ -294,29 +302,30 @@ private void addSNDToolStripMenuItem_Click(object sender, EventArgs e) {
myDialog.CheckFileExists = true;
myDialog.Multiselect = false;

if (myDialog.ShowDialog() == DialogResult.OK) {
if(myDialog.ShowDialog() == DialogResult.OK) {
audioFile = myDialog.FileName;

if (File.Exists(audioFile)) {
if(File.Exists(audioFile)) {
try {
if (!File.Exists(@"data\snd\" + Path.GetFileName(audioFile))) {
if(!File.Exists(@"data\snd\" + Path.GetFileName(audioFile))) {
Console.WriteLine(audioFile);
File.Copy(audioFile, @"data\snd\" + Path.GetFileName(audioFile), true);
xmlCreator();
} else {
}
else {
xmlCreator();
Console.WriteLine("File Already In Folder");
}
}
catch (System.IO.IOException) {
catch(System.IO.IOException) {
MessageBox.Show("The File Is Currlenty Open In Another Program.");
}
}
}
}

private void pictureBox1_Paint(object sender, PaintEventArgs e) {
using (Pen p = new Pen(Color.DarkRed)) {
using(Pen p = new Pen(Color.DarkRed)) {
p.DashStyle = DashStyle.Dot;

e.Graphics.DrawRectangle(p, 0, 0, 234, 140);
Expand All @@ -332,7 +341,7 @@ private void merubokkusuToolStripMenuItem_Click(object sender, EventArgs e) {
}

private void pictureBox1_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop))
if(e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
Expand All @@ -342,52 +351,59 @@ private void pictureBox1_DragDrop(object sender, DragEventArgs e) {
string[] audioFileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
audioFile = audioFileList[0];
MessageBox.Show(audioFile);
if (File.Exists(audioFile)) {
if(File.Exists(audioFile)) {
try {
if (!File.Exists(@"data\snd\" + Path.GetFileName(audioFile))) {
if(!File.Exists(@"data\snd\" + Path.GetFileName(audioFile))) {
Console.WriteLine(audioFile);
File.Copy(audioFile, @"data\snd\" + Path.GetFileName(audioFile), true);
xmlCreator();
} else {
}
else {
xmlCreator();
Console.WriteLine("File Already In Folder");
}
}
catch (System.IO.IOException) {
catch(System.IO.IOException) {
MessageBox.Show("The File Is Currlenty Open In Another Program.");
}
}
}

private void button1_Click_1(object sender, EventArgs e) {
if (listSnd.SelectedItems.Count > 0) {
if(listSnd.SelectedItems.Count > 0) {
ListViewItem sndItem = listSnd.SelectedItems[0];
string ID = sndItem.SubItems[2].Text;
string file = sndItem.SubItems[0].Text;
//Read and remove data in XML
XElement xEle = XElement.Load("chuuu.xml");
var qry = from element in xEle.Descendants()
where (string)element.Element("ID") == ID
select element;
if (qry.Count() > 0)
qry.First().Remove();
xEle.Save("chuuu.xml");
regKeys();
NumCount();
string ID = sndItem.SubItems[2].Text;
string file = sndItem.SubItems[0].Text;
//Read and remove data in XML
XElement xEle = XElement.Load("chuuu.xml");
var qry = from element in xEle.Descendants()
where (string)element.Element("ID") == ID
select element;
if(qry.Count() > 0)
qry.First().Remove();
xEle.Save("chuuu.xml");
if(idNumber.Max() == 1) {
if(File.Exists("chuuu.xml")) {
File.Delete("chuuu.xml");
}
}
regKeys();
NumCount();
}
}

private void NumCount() {
try {
if (idNumber.FirstOrDefault() == 0) {
if (File.Exists("chuuu.xml")) {
if(idNumber.FirstOrDefault() == 0) {
if(File.Exists("chuuu.xml")) {
File.Delete("chuuu.xml");
}
} else {
}
else {
HighestNumber = idNumber.Max();
Console.WriteLine("This is the highest number " + HighestNumber);
}
}catch(System.InvalidOperationException) {
}
catch(System.InvalidOperationException) {
MessageBox.Show("MEM");
}
}
Expand Down
1 change: 1 addition & 0 deletions Chuuu/Hotkey Editor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2742e9

Please sign in to comment.