示例#1
0
 internal static void KeyUp(object sender, KeyEventArgs e)
 {
     try
     {
         e.Handled          = true;
         e.SuppressKeyPress = true;
         Keyboard.KeyUp(e.KeyCode);
         if (!Recognize || !PttKeyDown)
         {
             return;
         }
         if (e.KeyValue != (int)PttKey.ToKey())
         {
             return;
         }
         PttKeyDown      = false;
         UI.Ellipse.Fill = new SolidColorBrush(Color.FromRgb(245, 39, 39));
         InternalSpeechRecognizer.Engine.RecognizeAsyncStop();
         Recognize = false;
     }
     catch (Exception ex)
     {
         IoQueue.Add(ex);
     }
 }
        private async void WebBrowserNavigated(object sender, NavigationEventArgs e)
        {
            // get token
            var url = e.Uri.Fragment;

            if (url.Contains("access_token") && url.Contains("#"))
            {
                url = (new Regex("#")).Replace(url, "?", 1);
                Kernel.FacebookAccessToken = HttpUtility.ParseQueryString(url).Get("access_token");
            }
            try
            {
                Kernel.FacebookClient = new FacebookClient(Kernel.FacebookAccessToken);
                dynamic friendsTaskResult = await Kernel.FacebookClient.GetTaskAsync("/me");

                await Dispatcher.BeginInvoke(new Action(() =>
                {
                    Kernel.FacebookName = friendsTaskResult.first_name + " " + friendsTaskResult.last_name;
                }), DispatcherPriority.Normal);

                dynamic image = await Kernel.FacebookClient.GetTaskAsync("/me/picture?redirect=0&height=200&type=normal&width=200");

                await Dispatcher.BeginInvoke(new Action(() =>
                {
                    Kernel.ProfilePicture = image["data"].url;
                    Kernel.UI.LoadImage();
                }), DispatcherPriority.Normal);

                Close();
            }
            catch (Exception ex)
            {
                IoQueue.Add("FacebookTwitterAuth " + ex.Message + " - " + ex.Source + " - " + ex.StackTrace);
            }
        }
示例#3
0
        /// <summary>
        /// Deletes a Directory and its Contents. Even ReadOnly files (run as admin)
        /// </summary>
        /// <param name="targetDir">Directory to delete</param>
        public static void DeleteDirectory(string targetDir)
        {
            try
            {
                var files = Directory.GetFiles(targetDir);
                var dirs  = Directory.GetDirectories(targetDir);

                foreach (var f in files)
                {
                    File.SetAttributes(f, FileAttributes.Normal);
                    DeleteFile(f);
                }

                foreach (var dir in dirs)
                {
                    DeleteDirectory(dir);
                }

                Directory.Delete(targetDir, false);
            }
            catch (Exception ex)
            {
                IoQueue.Add(ex);
            }
        }
示例#4
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs ex)
        {
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }
            Kernel.KeyboardHook.Unhook();
            MouseHook.UninstallHook();
            MessageBox.Show("Unfortunatelly, an exception occured. Please send the Logfile (found in the directory you ran this app from) to me, thanks!");

            IoQueue.Add("App::Domain->UnhandledException");
            var e = ex.ExceptionObject as Exception;

            if (e == null)
            {
                IoQueue.Add(ex.ToString());
                IoQueue.Add("Would have crashed the server? " + ex.IsTerminating);
            }
            else
            {
                IoQueue.Add(e.Source);
                IoQueue.Add(e.Message);
                IoQueue.Add(e.StackTrace);
                if (e.InnerException != null)
                {
                    IoQueue.Add(e.InnerException.Message);
                    IoQueue.Add(e.InnerException.StackTrace);
                }
                IoQueue.Add("Would have crashed the server? " + ex.IsTerminating);
            }
        }
示例#5
0
        private async void Headerimagebox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (!Headerimagebox.Text.Contains("http://"))
                {
                    BusyIndicator.IsBusy = true;
                    await Task.Delay(100);

                    var fileInfo = new FileInfo(Headerimagebox.Text);
                    Kernel.ScriptUploaderWindow.Title = "Size: " + fileInfo.Length / 1024 + "kbs";
                    try
                    {
                        Image img;
                        using (var msPng = new MemoryStream(File.ReadAllBytes(Headerimagebox.Text)))
                        {
                            img = Image.FromStream(msPng);
                        }
                        using (var msJpeg = new MemoryStream())
                        {
                            img.Save(msJpeg, ImageFormat.Jpeg);
                            File.WriteAllBytes(Headerimagebox.Text, msJpeg.ToArray());
                        }
                    }
                    catch { }
                    fileInfo = new FileInfo(Headerimagebox.Text);
                    Kernel.ScriptUploaderWindow.Title += " | New Size: " + fileInfo.Length / 1024 + "kbs";
                }
                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(Headerimagebox.Text, UriKind.Absolute);
                bitmap.EndInit();
                Headerimage.Source = bitmap;

                if (bitmap.Width > 1280 || bitmap.Height > 720)
                {
                    MessageBox.Show("Sorry, the image is too big. max is 1280x720");
                    return;
                }

                if (Headerimagebox.Text.Contains("cdn.votc.xyz") || Headerimagebox.Text == "")
                {
                    return;
                }

                var fileName = HashIt(Headerimagebox.Text) + ".png";
                await ImageUpload.Upload(Headerimagebox.Text, fileName);

                Headerimagebox.Text = "http://cdn.votc.xyz/votcstore/" + fileName;
            }
            catch (Exception ex)
            {
                IoQueue.Add(ex);
            }
            finally
            {
                BusyIndicator.IsBusy = false;
            }
        }
示例#6
0
        private async void submitbtn_Click(object sender, RoutedEventArgs e)
        {
            var fileContent = File.ReadAllText(@"Scripts\" + _scriptFile);

            if (fileContent.Contains("using System"))
            {
                if (Nametxtbx.Text != string.Empty && Authortxtbx.Text != string.Empty && Forapptxtbx.Text != string.Empty && Reqforetxtbx.Text != string.Empty && Descriptiontxtbx.Text != string.Empty && Commandstxtbx.Text != string.Empty && Passwordbox.Text != String.Empty && Storebadgebox.Text != string.Empty && Headerimagebox.Text != String.Empty)
                {
                    try
                    {
                        var builder = new StringBuilder();
                        builder.AppendLine(Nametxtbx.Text);
                        builder.AppendLine(Authortxtbx.Text);
                        builder.AppendLine(Forapptxtbx.Text);
                        builder.AppendLine(Reqforetxtbx.Text);
                        builder.AppendLine(Descriptiontxtbx.Text);
                        builder.AppendLine(Headerimagebox.Text);
                        builder.AppendLine(Storebadgebox.Text);
                        builder.AppendLine(Passwordbox.Text);
                        builder.AppendLine(Commandstxtbx.Text);
                        builder.AppendLine(fileContent);
                        if (_upload)
                        {
                            var data = Bit.CompressString(builder.ToString());
                            Kernel.ScriptUploaderWindow.Content = new UploadScriptProgress("Compressed " + builder.Length / 1024 + "kb into " + data.Length / 1024 + "kb using BitCompress!");
                            await Kernel.Channel.UploadScriptAsync(builder.ToString(), "");

                            if (fileContent.Contains("Socket") || fileContent.Contains("Listen"))
                            {
                                MessageBox.Show("Your script is potentially harmful so it will be manually reviewed and will only show up as Potentially Harmful Script in the meantime.", "Success!");
                            }
                            else
                            {
                                MessageBox.Show("Your script has been uploaded successfully.\n\nIf you can't instantly see it in the Gallery, the Filename was in use. Please rename your Script and Upload it again\nor use the correct password to update it!", "Success!");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        IoQueue.Add(ex);
                        MessageBox.Show("The server f**ed up. Please try again later...", "Oh shit.");
                    }
                }
                else
                {
                    MessageBox.Show("You need to fill out every field!", "Lol nope.");
                }
            }
            else
            {
                MessageBox.Show("You need to add 'using System; //VOTC LEGACY' to the top your Script!", "Lol nope.");
            }
        }
示例#7
0
        public static void Init()
        {
            if (_initialized)
            {
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
            IoQueue.Add("[CATCH::ALL] Started global exception handler.");
            _initialized = true;
        }
示例#8
0
        static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            Kernel.KeyboardHook.Unhook();
            MouseHook.UninstallHook();
            MessageBox.Show("Unfortunately, an exception occured. Please send the Logfile (found in the directory you ran this app from) to me, thanks!");

            IoQueue.Add("App::TaskScheduler_UnobservedTaskException");
            e.SetObserved();
            IoQueue.Add(e.Exception.Message);
            IoQueue.Add(e.Exception.Source);
            IoQueue.Add(e.Exception.StackTrace);
            IoQueue.Add(e.Exception.InnerException.Message);
            IoQueue.Add(e.Exception.InnerException.StackTrace);
        }
示例#9
0
 private void Microphoneset(object sender, RoutedEventArgs e)
 {
     try
     {
         var process = new Process
         {
             StartInfo =
             {
                 FileName = "RunDLL32 shell32.dll,Control_RunDLL mmsys.cpl,,1"
             }
         };
         process.Start();
     }
     catch (Exception x)
     {
         IoQueue.Add(x);
     }
 }
示例#10
0
 public static async void CacheImage(string imageUrl, string username)
 {
     try
     {
         using (var client = new WebClient())
         {
             if (!File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Cache\ChatCache\" + username + ".png"))
             {
                 await client.DownloadFileTaskAsync(imageUrl, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Cache\ChatCache\" + username + ".png");
             }
         }
         Kernel.ChatCache.TryAdd(imageUrl, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Cache\ChatCache\" + username + ".png");
     }
     catch (Exception ex)
     {
         IoQueue.Add(ex);
     }
 }
示例#11
0
 private async void scripts_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     BusyIndicator.IsBusy = true;
     try
     {
         var container = (StoreItem)((ListBox)sender).SelectedItem;
         Kernel.StoreWindow.Content = new StoreDetailView(await JsonConvert.DeserializeObjectAsync(await Kernel.Channel.DownloadScriptAsync(container.Title, "")));
     }
     catch (Exception ex)
     {
         IoQueue.Add(ex);
         MessageBox.Show("Sorry, this profile could not be opened.", "FAIL");
     }
     finally
     {
         BusyIndicator.IsBusy = false;
     }
 }
示例#12
0
 private void training_click(object sender, RoutedEventArgs e)
 {
     try
     {
         var process = new Process
         {
             StartInfo =
             {
                 FileName = "C:\\windows\\sysnative\\speech\\speechux\\SpeechUXWiz.exe", Arguments = "UserTraining"
             }
         };
         process.Start();
     }
     catch (Exception ex)
     {
         IoQueue.Add(ex);
     }
 }
示例#13
0
        /// <summary>
        /// Tries to delete a file up to 250 times. It will sleep the calling thread for 100ms each failed attempt.
        /// </summary>
        /// <param name="path">File path</param>
        /// <returns>True if deleted</returns>
        public static void DeleteFile(string path)
        {
            byte tries = 0;

            while (tries < 250)
            {
                tries++;
                try
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                    File.Delete(path);
                    return;
                }
                catch (Exception ex)
                {
                    IoQueue.Add(ex);
                    Thread.Sleep(100);
                }
            }
            Kernel.UI.DisplayCmd("File " + path + " could not be deleted!");
        }
示例#14
0
 internal static void KeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         e.Handled = true;
         Keyboard.KeyDown(e.KeyCode);
         if (Recognize || PttKeyDown)
         {
             return;
         }
         if (e.KeyValue != (int)PttKey.ToKey())
         {
             return;
         }
         PttKeyDown      = true;
         UI.Ellipse.Fill = new SolidColorBrush(Color.FromRgb(39, 245, 46));
         InternalSpeechRecognizer.Engine.RecognizeAsync(RecognizeMode.Multiple);
         Recognize = true;
     }
     catch (Exception ex)
     {
         IoQueue.Add(ex);
     }
 }
示例#15
0
        public void Compile()
        {
            Kernel.UI?.DisplayCmd("Recompiling scripts...", false);
            try
            {
                var files         = Directory.GetFiles(_settings.ScriptLocation, "*.cs");
                var preparedFiles = files.ToDictionary(file => "Scripts\\" + Path.GetFileName(file), File.ReadAllText);

                var assemblies = AppDomain.CurrentDomain.GetAssemblies();

                var cSharpCodeProvider = new CSharpCodeProvider();
                var compilerParameters = new CompilerParameters
                {
                    GenerateInMemory        = true,
                    IncludeDebugInformation = false,
                    TempFiles = new TempFileCollection("Cache\\Temp", false)
                };

                foreach (var assembly in assemblies)
                {
                    try
                    {
                        compilerParameters.ReferencedAssemblies.Add(assembly.Location);
                    }
                    catch (Exception ex)
                    {
                        IoQueue.Add(ex);
                    }
                }
                foreach (var type in _settings.Types.Values)
                {
                    compilerParameters.ReferencedAssemblies.Add(Assembly.GetAssembly(type).Location);
                }

                foreach (var file in preparedFiles)
                {
                    var results = cSharpCodeProvider.CompileAssemblyFromFile(compilerParameters, file.Key);
                    if (results.Errors.Count != 0)
                    {
                        foreach (var error in results.Errors.Cast <CompilerError>().Where(err => !err.IsWarning))
                        {
                            Kernel.UI?.DisplayCmd("Buggy Script: " + Path.GetFileName(file.Key));
                            if (Kernel.DebugMode)
                            {
                                Kernel.UI?.DisplayCmd(error + error.FileName);
                            }
                        }
                    }
                    else
                    {
                        Kernel.UI?.DisplayCmd("Successfully compiled " + Path.GetFileName(file.Key), false);
                        foreach (var method in (from compiledType in results.CompiledAssembly.GetTypes()
                                                from method in compiledType.GetMethods()
                                                where method.IsStatic
                                                select method).Where(reflectedMethod => reflectedMethod.ReflectedType != null))
                        {
                            if (method.Name == "IncommingVoicePacket")
                            {
                                CompiledMethods.TryAdd(Path.GetFileName(file.Key) + "IncomingVoicePacket", method);
                            }
                            if (method.Name == "SetUp")
                            {
                                CompiledMethods.TryAdd(Path.GetFileName(file.Key) + "SetUp", method);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (IoQueue.L != null)
                {
                    IoQueue.Add(e);
                }
            }
        }
示例#16
0
        private async void page_Loaded(object sender, RoutedEventArgs e)
        {
            await HardwareInterface.Initialize();

            DisplayCmd("Double click any item in here to read its content");
            DisplayCmd("Go to 'File -> Profiles' to load a profile!");
            DisplayCmd("If you're new, go to the store and download one!");
            try
            {
                if (sender != null && e != null)
                {
                    await Task.Run(async() =>
                    {
                        var builder = new StringBuilder();
                        foreach (var script in Directory.GetFiles("Scripts\\"))
                        {
                            var info       = new FileInfo(script);
                            var localHash  = info.CreationTimeUtc.ToString(CultureInfo.InvariantCulture);
                            var scriptName = Path.GetFileName(script);
                            string remoteHash;
                            try
                            {
                                remoteHash = await Kernel.Channel.GetScriptHashAsync(scriptName, "");
                            }
                            catch
                            {
                                continue;
                            }
                            var localTime  = DateTime.Parse(localHash);
                            var remoteTime = DateTime.Parse(remoteHash);

                            if (localTime >= remoteTime)
                            {
                                continue;
                            }

                            builder.AppendLine("New version of '" + scriptName + "' available in the store!");
                            if (!Directory.Exists(@"Cache\Store\"))
                            {
                                continue;
                            }
                            if (File.Exists(@"Cache\Store\" + scriptName?.Replace(".cs", ".badge")))
                            {
                                File.Delete(@"Cache\Store\" + scriptName?.Replace(".cs", ".badge"));
                            }
                            if (File.Exists(@"Cache\Store\" + scriptName?.Replace(".cs", ".header")))
                            {
                                File.Delete(@"Cache\Store\" + scriptName?.Replace(".cs", ".header"));
                            }
                        }
                        if (!string.IsNullOrEmpty(builder.ToString()))
                        {
                            MessageBox.Show(builder.ToString());
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("VOTC Master Server offline. No updates could be fetched :(");
                IoQueue.Add(ex);
            }
            InternalSpeechRecognizer.PrepareSpeech();
            if (string.IsNullOrEmpty(Kernel.FacebookAccessToken))
            {
                return;
            }
            try
            {
                Kernel.FacebookClient = new FacebookClient(Kernel.FacebookAccessToken);
                dynamic friendsTaskResult = await Kernel.FacebookClient.GetTaskAsync("/me");

                Kernel.FacebookName = friendsTaskResult.first_name + " " + friendsTaskResult.last_name;
                dynamic facebookImage = await Kernel.FacebookClient.GetTaskAsync("/me/picture?redirect=0&height=200&type=normal&width=200");

                Kernel.ProfilePicture = facebookImage["data"].url;
                Kernel.UI.LoadImage();
            }
            catch
            {
                //Ignored
            }
        }
示例#17
0
        private async void Storebadgebox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (!Storebadgebox.Text.Contains("http://"))
                {
                    BusyIndicator.IsBusy = true;
                    await Task.Delay(100);

                    var fileInfo = new FileInfo(Storebadgebox.Text);
                    Kernel.ScriptUploaderWindow.Title = "Size: " + fileInfo.Length / 1024 + "kbs";
                    var info = new ProcessStartInfo
                    {
                        FileName    = "Ressources\\optipng.exe",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        Arguments   = "\"" + Storebadgebox.Text + "\" -o7"
                    };
                    using (var p = Process.Start(info))
                    {
                        p?.WaitForExit();
                    }
                    info = new ProcessStartInfo
                    {
                        FileName    = "Ressources\\pngcrush.exe",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        Arguments   = "\"" + Storebadgebox.Text + "\" -brute"
                    };
                    using (var p = Process.Start(info))
                    {
                        p?.WaitForExit();
                    }
                    info = new ProcessStartInfo
                    {
                        FileName    = "Ressources\\pngout",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        Arguments   = "\"" + Storebadgebox.Text + "\" /y /r"
                    };
                    using (var p = Process.Start(info))
                    {
                        p?.WaitForExit();
                    }
                    await Task.Delay(100);

                    fileInfo = new FileInfo(Storebadgebox.Text);
                    Kernel.ScriptUploaderWindow.Title += " | New Size: " + fileInfo.Length / 1024 + "kbs";
                }

                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(Storebadgebox.Text, UriKind.Absolute);
                bitmap.EndInit();
                BadgeimagImage.Fill = new ImageBrush(bitmap);

                if (bitmap.Width > 256 || bitmap.Height > 256 || bitmap.Width != bitmap.Height)
                {
                    MessageBox.Show("Sorry, either the image is too big or not a square. Make it 128x128 for best results, max is 256x256");
                    return;
                }

                if (Storebadgebox.Text.Contains("cdn.votc.xyz") || Storebadgebox.Text == "")
                {
                    return;
                }

                var fileName = HashIt(Storebadgebox.Text) + ".png";
                await ImageUpload.Upload(Storebadgebox.Text, fileName);

                Storebadgebox.Text = "http://cdn.votc.xyz/votcstore/" + fileName;
            }
            catch (Exception ex)
            {
                IoQueue.Add(ex);
            }
            finally
            {
                BusyIndicator.IsBusy = false;
            }
        }
示例#18
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Kernel.FacebookName) && string.IsNullOrEmpty(Kernel.TwitterUsername))
            {
                MessageBox.Show("You have to login to facebook or twitter first so we can identify you.");
                Close();
                return;
            }
            try
            {
                Client.Connect("eubfwcf.cloudapp.net", 700);
                Stream = Client.GetStream();
                SendMessage("Connected!");
                while (true)
                {
                    try
                    {
                        var data  = new byte[4096];
                        var bytes = await Stream.ReadAsync(data, 0, data.Length);

                        var json      = Encoding.UTF8.GetString(data, 0, bytes).Trim().Replace("\0", string.Empty);
                        var j         = json.Split('}')[0] + "}";
                        var entryJson = await JsonConvert.DeserializeObjectAsync <ChatEntryJson>(j);

                        if (entryJson == null)
                        {
                            continue;
                        }

                        var entry = new ChatEntry(entryJson.ImageUrl, entryJson.Text, entryJson.Username, false);

                        if (entry.UserName.Text == Kernel.CustomName)
                        {
                            continue;
                        }
                        await Dispatcher.BeginInvoke(new Action(() =>
                        {
                            SoundThingy.Stop();
                            SoundThingy.Position = TimeSpan.Zero;
                            SoundThingy.Play();
                            var panel = new StackPanel {
                                MaxWidth = Kernel.UI.Width, Orientation = Orientation.Horizontal, Background = new SolidColorBrush(Color.FromRgb(194, 224, 224))
                            };
                            var block = new TextBlock {
                                Text = " said: ", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, TextWrapping = TextWrapping.Wrap
                            };
                            var block2 = new TextBlock {
                                Text = "  ", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, TextWrapping = TextWrapping.Wrap
                            };
                            panel.Children.Add(entry.Img);
                            panel.Children.Add(block2);
                            panel.Children.Add(entry.UserName);
                            panel.Children.Add(block);
                            panel.Children.Add(entry.Text);
                            ChatBox.Children.Add(panel);
                            ScrollViewer.ScrollToEnd();
                        }), DispatcherPriority.Normal);
                    }
                    catch (Exception ex)
                    {
                        IoQueue.Add(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not connect to the chat.", "fail");
                IoQueue.Add(ex);
                Close();
            }
        }