Exemplo n.º 1
0
        private void OnRemove(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = treeView.SelectedItem as TreeViewItem;

            TreeViewItem parent = item.Parent as TreeViewItem;

            if (item != null && parent != null)
            {
                string type = "Folder";
                if (item.Tag is Setup)
                {
                    type = setupType.ToString();
                }
                var result = TriggerMessageBox.Show(Window.GetWindow(this), MessageIcon.Question, "Are you sure you want to remove this " + type.ToLower() + "?", "Remove " + type, MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    TreeViewItem newSelection = FindMoveItem(item, -1);
                    if (newSelection == null)
                    {
                        newSelection = FindMoveItem(item, 1);
                    }
                    parent.Items.Remove(item);
                    UpdateButtons();

                    if (newSelection != null)
                    {
                        newSelection.IsSelected = true;
                        newSelection.Focus();
                    }
                    Modified = true;
                }
            }
        }
Exemplo n.º 2
0
        //========== CONNECTION ==========
        #region Connection

        /**<summary>Starts up the host server.</summary>*/
        private void HostStartup()
        {
            int port = numericHostPort.Value;

            server = new Server();
            server.MessageReceived      += OnHostMessageReceived;
            server.ClientConnected      += OnHostClientConnected;
            server.ClientConnectionLost += OnHostClientConnectionLost;
            server.Error += OnHostError;
            if (!server.Start(port))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Failed to start host server!", "Host Error");
                server = null;
            }
            else
            {
                Dispatcher.Invoke(() => {
                    comboBoxSyncType.IsEnabled     = false;
                    textBoxHostPassword.IsEnabled  = false;
                    numericHostPort.IsEnabled      = false;
                    numericHostWait.IsEnabled      = true;
                    textBoxHostNextSong.IsEnabled  = true;
                    buttonHostAssignSong.IsEnabled = true;
                    listViewClients.IsEnabled      = true;
                    buttonHostStartup.Content      = "Shutdown";
                });
            }
        }
Exemplo n.º 3
0
        private void OnUnpack(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBoxResult.No;

            if (!ValidPathTest() || !ValidPathTest2(false))
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to unpack localizations from the current Terraria executable?", "Unpack Localizations", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            try {
                LocalizationPacker.Unpack();
                result = TriggerMessageBox.Show(this, MessageIcon.Info, "Localizations successfully unpacked! Would you like to open the output folder?", "Localizations Unpacked", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    Process.Start(LocalizationPacker.OutputDirectory);
                }
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while unpacking localizations! Would you like to see the error?", "Unpack Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
        }
Exemplo n.º 4
0
        private void OnRestore(object sender, RoutedEventArgs e)
        {
            string input  = Config.Backup.FolderBackup;
            string output = Config.Backup.FolderContent;

            if (!Helpers.DirectoryExistsSafe(input))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find the Backup folder.", "Invalid Path");
                return;
            }
            if (!Helpers.DirectoryExistsSafe(output))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find the Content folder.", "Invalid Path");
                return;
            }
            if (string.Compare(Path.GetFullPath(input), Path.GetFullPath(output), true) == 0)
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Restore paths cannot be the same folder.", "Invalid Path");
                return;
            }

            input  = Helpers.FixPathSafe(input);
            output = Helpers.FixPathSafe(output);
            Thread thread = new Thread(() => {
                Processing.RestoreFiles(input, output);
            });

            Processing.StartProgressThread(this, "Restoring...", Config.AutoCloseProgress, Config.CompressImages, Config.CompletionSound, thread);
        }
        private void OnAddMidi(object sender, RoutedEventArgs e)
        {
            Stop();
            loaded = false;

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter      = "Midi Files|*.mid;*.midi|All Files|*.*";
            dialog.FilterIndex = 0;
            var result = dialog.ShowDialog(this);

            if (result.HasValue && result.Value)
            {
                Midi midi = new Midi();
                if (midi.Load(dialog.FileName))
                {
                    Config.Midis.Add(midi);
                    Config.MidiIndex = Config.MidiCount - 1;
                    listMidis.Items.Add(midi.ProperName);
                    listMidis.SelectedIndex = Config.MidiIndex;
                    listMidis.ScrollIntoView(listMidis.Items[Config.MidiIndex]);
                    UpdateMidi();
                }
                else
                {
                    var result2 = TriggerMessageBox.Show(this, MessageIcon.Error, "Error when loading the selected midi! Would you like to see the error?", "Load Error", MessageBoxButton.YesNo);
                    if (result2 == MessageBoxResult.Yes)
                    {
                        ErrorMessageBox.Show(midi.LoadException, true);
                    }
                }
            }

            loaded = true;
        }
Exemplo n.º 6
0
        private void OnRestore(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest(false))
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to restore the current Terraria executable to its backup?", "Restore Terraria", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            if (!File.Exists(LocalizationPacker.BackupPath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find Terraria backup!", "Missing Backup");
                return;
            }
            try {
                LocalizationPacker.Restore();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully restored!", "Terraria Restored");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while restoring Terraria! Would you like to see the error?", "Restore Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
            }
        }
        //--------------------------------
        #region Patching

        private void OnPatch(object sender = null, RoutedEventArgs e = null)
        {
            MessageBoxResult result;

            if (!ValidPathTest())
            {
                return;
            }
            if (!File.Exists(Patcher.ExePath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find Terraria executable!", "Missing Exe");
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to patch the current Terraria executable?", "Patch Terraria", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            try {
                Patcher.Patch();
                SaveItemModificationsXml();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully patched!", "Terraria Patched");
            }
            catch (AlreadyPatchedException) {
                TriggerMessageBox.Show(this, MessageIcon.Error, "This executable has already been patched by Item Modifier! Use Restore & Patch instead.", "Already Patched");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while patching Terraria! Would you like to see the error?", "Patch Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
        }
        private void OnUpdateContent(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest())
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to update the rupee content files?", "Update Rupees", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            try {
                ContentReplacer.Replace();
                ContentReplacer.SaveXmlConfiguration();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Rupee content files successfully updated!", "Rupees Updated");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while updating rupee content files! Would you like to see the error?", "Patch Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
        }
        private void OnRemoveMidi(object sender, RoutedEventArgs e)
        {
            Stop();
            loaded = false;

            if (Config.HasMidi)
            {
                var result = TriggerMessageBox.Show(this, MessageIcon.Warning, "Are you sure you want to remove this midi?", "Remove Midi", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    Config.Midis.RemoveAt(Config.MidiIndex);
                    listMidis.Items.RemoveAt(Config.MidiIndex);

                    if (Config.MidiIndex > 0)
                    {
                        Config.MidiIndex--;
                    }
                    else if (Config.MidiIndex >= Config.MidiCount)
                    {
                        Config.MidiIndex = Config.MidiCount - 1;
                    }

                    listMidis.SelectedIndex = Config.MidiIndex;
                    if (Config.HasMidi)
                    {
                        listMidis.ScrollIntoView(listMidis.Items[Config.MidiIndex]);
                    }

                    UpdateMidi();
                }
            }

            loaded = true;
        }
        private void OnRestoreAndPatch(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest())
            {
                return;
            }
            if (!File.Exists(Patcher.BackupPath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Error, "Could not find Terraria backup!", "Missing Backup");
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to restore Terraria from its backup and then patch it?", "Patch & Restore Terraria", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            if (File.Exists(Patcher.ExePath) && IL.GetAssemblyVersion(Patcher.BackupPath) < IL.GetAssemblyVersion(Patcher.ExePath))
            {
                result = TriggerMessageBox.Show(this, MessageIcon.Warning, "The backed up Terraria executable is an older game version. Are you sure you want to restore it?", "Older Version", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            if (!CheckSupportedVersion(Patcher.BackupPath))
            {
                return;
            }
            try {
                Patcher.Restore(false);
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while restoring Terraria! Would you like to see the error?", "Restore Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
            try {
                Patcher.Patch();
                ContentReplacer.Replace();
                ContentReplacer.SaveXmlConfiguration();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully restored and patched!", "Terraria Repatched");
            }
            catch (AlreadyPatchedException) {
                TriggerMessageBox.Show(this, MessageIcon.Error, "The backup executable has already been patched by Rupee Replacer!", "Already Patched");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while patching Terraria! Would you like to see the error?", "Patch Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
            }
        }
Exemplo n.º 11
0
        private void OnHostError(Server server, Exception ex)
        {
            var result = TriggerMessageBox.Show(this, MessageIcon.Error, "A host error occurred. Would you like to see the error?", "Host Error", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                ErrorMessageBox.Show(ex);
            }
        }
        public void OnMidiKeybindChanged(object sender, KeybindChangedEventArgs e)
        {
            if (!loaded)
            {
                return;
            }

            string name = "";

            if (e.New != Keybind.None)
            {
                if (e.New == Config.Keybinds.Play)
                {
                    name = "Play Midi";
                }
                else if (e.New == Config.Keybinds.Pause)
                {
                    name = "Pause Midi";
                }
                else if (e.New == Config.Keybinds.Stop)
                {
                    name = "Stop Midi";
                }
                else if (e.New == Config.Keybinds.Close)
                {
                    name = "Close Window";
                }
                else if (e.New == Config.Keybinds.Mount)
                {
                    name = "Toggle Mount";
                }
                else
                {
                    for (int i = 0; i < Config.MidiCount; i++)
                    {
                        if (i != Config.MidiIndex && e.New == Config.Midis[i].Keybind)
                        {
                            name = Config.Midis[i].ProperName;
                            break;
                        }
                    }
                }
            }
            if (name == "")
            {
                // The name can safely be changed
                Config.Midi.Keybind = e.New;
            }
            else
            {
                // Nag the user about poor life choices
                TriggerMessageBox.Show(this, MessageIcon.Error, "Keybind is already in use by the '" + name + "' keybind!", "Keybind in Use");
                keybindReaderMidi.Keybind = e.Previous;
            }
        }
        private void OnRestore(object sender = null, RoutedEventArgs e = null)
        {
            MessageBoxResult result;
            bool             cleanup = false;

            if (!ValidPathTest())
            {
                return;
            }
            if (!File.Exists(Patcher.BackupPath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find Terraria backup!", "Missing Backup");
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Would you like to restore the current Terraria executable to its backup and cleanup the required files or just restore the backup?", "Restore Terraria", MessageBoxButton.YesNoCancel, "Cleanup & Restore", "Restore Only");
            if (result == MessageBoxResult.Cancel)
            {
                return;
            }
            cleanup = result == MessageBoxResult.Yes;
            if (File.Exists(Patcher.ExePath) && IL.GetAssemblyVersion(Patcher.BackupPath) < IL.GetAssemblyVersion(Patcher.ExePath))
            {
                result = TriggerMessageBox.Show(this, MessageIcon.Warning, "The backed up Terraria executable is an older game version. Are you sure you want to restore it?", "Older Version", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            try {
                Patcher.Restore(cleanup);
                // Clean up directory and remove config file
                if (cleanup)
                {
                    string configPath = Path.Combine(Patcher.ExeDirectory, ItemModifier.ConfigName);
                    string logPath    = Path.Combine(Patcher.ExeDirectory, ErrorLogger.LogName);
                    if (File.Exists(configPath))
                    {
                        File.Delete(configPath);
                    }
                    if (File.Exists(logPath))
                    {
                        File.Delete(logPath);
                    }
                }
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully restored!", "Terraria Restored");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while restoring Terraria! Would you like to see the error?", "Restore Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
            }
        }
Exemplo n.º 14
0
        public App()
        {
            bool isnew;

            m = new Mutex(true, "Global\\" + appGuid, out isnew);
            if (!isnew)
            {
                TriggerMessageBox.Show(null, "Cannot run more than one instance of Trigger's PC at a time.");
                Environment.Exit(0);
            }
        }
Exemplo n.º 15
0
        //============ CONFIG ============
        #region Config

        /**<summary>Loads the config file.</summary>*/
        private bool LoadConfig()
        {
            if (!Config.Load())
            {
                MessageBoxResult result = TriggerMessageBox.Show(this, MessageIcon.Error, "Error while trying to load config. Would you like to see the error?", "Load Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(Config.LastException);
                }
                return(false);
            }
            return(true);
        }
        // Media Events ---------------------------------------------------------------

        private void OnMediaOpened(object sender, RoutedEventArgs e)
        {
            supressEvents          = true;
            sliderPosition.Value   = 0;
            sliderPosition.Maximum = PGControl.FrameDuration;

            // Choose a tick frequency that's not *too* frequent
            double frameRate    = Math.Round(Media.VideoFrameRate);
            double totalSeconds = PGControl.Duration.TotalSeconds;

            if (totalSeconds <= 60)
            {
                sliderPosition.TickFrequency = frameRate;
            }
            else if (totalSeconds <= 60 * 2)
            {
                sliderPosition.TickFrequency = frameRate * 2;
            }
            else if (totalSeconds <= 60 * 5)
            {
                sliderPosition.TickFrequency = frameRate * 5;
            }
            else if (totalSeconds <= 60 * 10)
            {
                sliderPosition.TickFrequency = frameRate * 30;
            }
            else
            {
                sliderPosition.TickFrequency = frameRate * 60;
            }

            spinnerFrame.Maximum  = PGControl.FrameDuration;
            supressEvents         = false;
            labelDuration.Content = PGControl.Duration.ToString(@"mm\:ss\.ff");
            if (Media.NaturalVideoWidth > MaxVideoDimensions || Media.NaturalVideoHeight > MaxVideoDimensions)
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Video dimensions are too large to be supported by the player!", "Video too Large");
                forceCloseVideo = true;
                return;
            }

            double oldScale = VideoScale;
            Size   oldSize  = new Size(Width, Height);

            baseWidth  = Media.NaturalVideoWidth;
            baseHeight = Media.NaturalVideoHeight;
            MinWidth   = Math.Max(finalMinWidth, playerOffset.Width + (baseWidth * 2));
            MinHeight  = playerOffset.Height + baseHeight;
            MakeRoomForNewVideoSize(oldScale, oldSize);
        }
Exemplo n.º 17
0
 private void OnOpenTerrariaFolder(object sender, RoutedEventArgs e)
 {
     if (Config.TerrariaContentDirectory != string.Empty)
     {
         string dir = Config.TerrariaContentDirectory;
         try {
             dir = Path.GetDirectoryName(Config.TerrariaContentDirectory);
             Process.Start(dir);
         }
         catch {
             TriggerMessageBox.Show(this, MessageIcon.Warning, "Failed to locate Terraria folder.", "Missing Folder");
         }
     }
 }
Exemplo n.º 18
0
        //--------------------------------
        #region Extracting

        private void OnExtract(object sender, RoutedEventArgs e)
        {
            string input         = Config.Extract.CurrentInput;
            string output        = (Config.Extract.UseInput ? Config.Extract.CurrentInput : Config.Extract.CurrentOutput);
            bool   allowImages   = Config.Extract.AllowImages;
            bool   allowSounds   = Config.Extract.AllowSounds;
            bool   allowFonts    = Config.Extract.AllowFonts;
            bool   allowWaveBank = Config.Extract.AllowWaveBank;

            Thread thread;

            if (Config.Extract.Mode == InputModes.Folder)
            {
                if (!Helpers.DirectoryExistsSafe(input))
                {
                    TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find the input folder.", "Invalid Path");
                    return;
                }
                if (!Helpers.IsPathValid(output))
                {
                    TriggerMessageBox.Show(this, MessageIcon.Warning, "Output folder path is invalid.", "Invalid Path");
                    return;
                }
                input  = Helpers.FixPathSafe(input);
                output = Helpers.FixPathSafe(output);
                thread = new Thread(() => {
                    Processing.ExtractAll(input, output, allowImages, allowSounds, allowFonts, allowWaveBank);
                });
            }
            else
            {
                if (!Helpers.FileExistsSafe(input))
                {
                    TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find the input file.", "Invalid Path");
                    return;
                }
                if (!Helpers.IsPathValid(output))
                {
                    TriggerMessageBox.Show(this, MessageIcon.Warning, "Output file path is invalid.", "Invalid Path");
                    return;
                }
                input  = Helpers.FixPathSafe(input);
                output = Helpers.FixPathSafe(output);
                thread = new Thread(() => {
                    Processing.ExtractSingleFile(input, output);
                });
            }
            Processing.StartProgressThread(this, "Extracting...", Config.AutoCloseProgress, Config.CompressImages, Config.CompletionSound, thread);
        }
Exemplo n.º 19
0
        //========= CONSTRUCTORS =========
        #region Constructors

        /**<summary>Constructs the WPF app.</summary>*/
        public App()
        {
            // Setup embedded assembly resolving
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssemblies;

            // We only want to run one instance at a time. Otherwise the temporary
            // output files will be modified by two or more programs.
            bool isNew;

            m = new Mutex(true, "Global\\" + GUID, out isNew);
            if (!isNew)
            {
                TriggerMessageBox.Show(null, MessageIcon.Warning, "Quick Wave Bank is already running. Cannot run more than one instance at the same time.", "Already Running");
                Environment.Exit(0);
            }
        }
 /**<summary>Checks if the path is valid.</summary>*/
 private bool ValidPathTest()
 {
     if (Patcher.ExePath == "")
     {
         TriggerMessageBox.Show(this, MessageIcon.Warning, "The Terraria path cannot be empty!", "Invalid Path");
         return(false);
     }
     try {
         Path.GetDirectoryName(Patcher.ExePath);
         return(true);
     }
     catch (ArgumentException) {
         TriggerMessageBox.Show(this, MessageIcon.Warning, "You must enter a valid Terraria path!", "Invalid Path");
         return(false);
     }
 }
Exemplo n.º 21
0
 /**<summary>Saves the config file.</summary>*/
 private bool SaveConfig(bool silent)
 {
     if (!Config.Save())
     {
         if (!silent)
         {
             MessageBoxResult result = TriggerMessageBox.Show(this, MessageIcon.Error, "Error while trying to save config. Would you like to see the error?", "Save Error", MessageBoxButton.YesNo);
             if (result == MessageBoxResult.Yes)
             {
                 ErrorMessageBox.Show(Config.LastException);
             }
         }
         return(false);
     }
     return(true);
 }
Exemplo n.º 22
0
 private void OnOpenInputFolder(object sender, RoutedEventArgs e)
 {
     try {
         if (Directory.Exists(LocalizationPacker.InputDirectory))
         {
             Process.Start(LocalizationPacker.InputDirectory);
         }
         else
         {
             TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not locate the Input folder! Cannot open folder.", "Missing Folder");
         }
     }
     catch {
         TriggerMessageBox.Show(this, MessageIcon.Warning, "The current path to Input is invalid! Cannot open folder.", "Invalid Path");
     }
 }
 private void OnOpenTerrariaFolder(object sender, RoutedEventArgs e)
 {
     try {
         if (Directory.Exists(Patcher.ExeDirectory))
         {
             Process.Start(Patcher.ExeDirectory);
         }
         else
         {
             TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not locate the Terraria folder! Cannot open folder.", "Missing Folder");
         }
     }
     catch {
         TriggerMessageBox.Show(this, MessageIcon.Warning, "The current path to Terraria is invalid! Cannot open folder.", "Invalid Path");
     }
 }
Exemplo n.º 24
0
        //========== CONNECTION ==========
        #region Connection

        /**<summary>Attempts to connect to the host.</summary>*/
        private void ClientConnect()
        {
            // Validate input
            int       port = Config.Syncing.ClientPort;
            IPAddress ip   = IPAddress.Loopback;

            if (Config.Syncing.ClientIPAddress != "" && !IPAddress.TryParse(Config.Syncing.ClientIPAddress, out ip))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "The entered IP address in invalid!", "Invalid IP");
                return;
            }
            if (Config.Syncing.ClientUsername == "")
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Cannot connect with an empty username!", "Invalid Username");
                return;
            }

            // Connect to the host
            client = new ClientConnection();
            client.MessageReceived += OnClientMessageReceived;
            client.ConnectionLost  += OnClientConnectionLost;
            if (!client.Connect(ip, port))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Failed to connect to server!", "Connection Failed");
                client = null;
            }
            else
            {
                // Final setup before waiting to login
                // Set the control states
                Dispatcher.Invoke(() => {
                    comboBoxSyncType.IsEnabled      = false;
                    textBoxClientIP.IsEnabled       = false;
                    numericClientPort.IsEnabled     = false;
                    textBoxClientUsername.IsEnabled = false;
                    textBoxClientPassword.IsEnabled = false;
                    textBoxClientNextSong.IsEnabled = false;
                    buttonClientConnect.IsEnabled   = false;
                    buttonClientConnect.Content     = "Connecting...";
                });

                clientTimeout.Start();

                client.Send(new StringCommand(Commands.Login, Config.Syncing.ClientUsername, Config.Syncing.ClientPassword));
            }
        }
Exemplo n.º 25
0
 private void OnClientConnectingTimeout(object sender, ElapsedEventArgs e)
 {
     if (!clientAccepted && client != null)
     {
         Dispatcher.Invoke(() => {
             OnClientConnect(null, new RoutedEventArgs());
             if (reconnectWatch.ElapsedMilliseconds < 1500 + (int)clientTimeout.Interval)
             {
                 TriggerMessageBox.Show(this, MessageIcon.Warning, "Failed to login! You are trying to reconnect to the server too quickly. Wait at least one second before reconnecting.", "Login Failed");
             }
             else
             {
                 TriggerMessageBox.Show(this, MessageIcon.Warning, "Failed to login!", "Login Failed");
             }
         });
     }
 }
Exemplo n.º 26
0
        //--------------------------------
        #region Scripting

        private void OnRunScript(object sender, RoutedEventArgs e)
        {
            string input = Config.Script.File;

            Thread thread;

            if (!Helpers.FileExistsSafe(input))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find the script file.", "Invalid Path");
                return;
            }
            input  = Helpers.FixPathSafe(input);
            thread = new Thread(() => {
                Processing.RunScript(input);
            });
            Processing.StartProgressThread(this, "Running Script...", Config.AutoCloseProgress, Config.CompressImages, Config.CompletionSound, thread);
        }
        //============= PLAY =============
        #region Play

        /**<summary>Starts or continues the song.</summary>*/
        private void Play()
        {
            if (Config.HasMidi)
            {
                firstNote = true;
                TerrariaWindowLocator.Update(true);
                if (!TerrariaWindowLocator.HasFocus)
                {
                    TerrariaWindowLocator.Focus();
                    Thread.Sleep(400);
                }
                if (TerrariaWindowLocator.IsOpen)
                {
                    clientArea = TerrariaWindowLocator.ClientArea;
                    noteWatch.Restart();

                    // When the sequencer finishes it leaves its position at 1
                    if (sequencer.Position <= 1)
                    {
                        sequencer.Start();
                    }
                    else
                    {
                        sequencer.Continue();
                    }

                    checkCount = 0;
                    Dispatcher.Invoke(() => {
                        toggleButtonStop.IsChecked  = false;
                        toggleButtonPlay.IsChecked  = true;
                        toggleButtonPause.IsChecked = false;
                        playbackUITimer.Start();
                    });
                }
                else
                {
                    Dispatcher.Invoke(() => {
                        toggleButtonPlay.IsChecked = false;
                        TriggerMessageBox.Show(this, MessageIcon.Warning, "You cannot play a midi when Terraria isn't running! Have you specified the correct executable name in Options?", "Terraria not Running");
                    });
                }
            }
        }
        //--------------------------------
        #region Menu Items

        private void OnLaunchTerraria(object sender, RoutedEventArgs e)
        {
            try {
                if (File.Exists(Patcher.ExePath))
                {
                    ProcessStartInfo start = new ProcessStartInfo();
                    start.FileName         = Patcher.ExePath;
                    start.Arguments        = TerrariaLocator.FindTerraLauncherSaveDirectory(Patcher.ExePath);
                    start.WorkingDirectory = Patcher.ExeDirectory;
                    Process.Start(start);
                }
                else
                {
                    TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not locate the Terraria executable! Cannot launch Terraria.", "Missing Executable");
                }
            }
            catch {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "The current path to Terraria is invalid! Cannot launch Terraria.", "Invalid Path");
            }
        }
 private void OnChannelMessagePlayed(object sender, ChannelMessageEventArgs e)
 {
     if (Config.Midi.IsMessagePlayable(e) && (watch.ElapsedMilliseconds >= Config.UseTime * 1000 / 60 + 2 || firstNote))
     {
         if (Config.ChecksEnabled)
         {
             checkCount++;
             if (!TerrariaWindowLocator.Update(Config.ChecksEnabled && checkCount > Config.CheckFrequency))
             {
                 Pause();
                 Dispatcher.Invoke(() => {
                     TriggerMessageBox.Show(this, MessageIcon.Error, "Failed to keep track of the Terraria Window!", "Tracking Error");
                 });
                 return;
             }
             if (checkCount > Config.CheckFrequency)
             {
                 checkCount = 0;
             }
             if (!TerrariaWindowLocator.HasFocus)
             {
                 TerrariaWindowLocator.Focus();
                 Thread.Sleep(100);
                 return;
             }
             if (!TerrariaWindowLocator.IsOpen)
             {
                 Pause();
                 Dispatcher.Invoke(() => {
                     TriggerMessageBox.Show(this, MessageIcon.Warning, "Terraria window has been closed.", "Terraria Closed");
                 });
                 return;
             }
             clientArea = TerrariaWindowLocator.ClientArea;
         }
         firstNote = false;
         int note = e.Message.Data1 - 12 * (Config.Midi.GetTrackSettingsByTrackObj(e.Track).OctaveOffset + 1) + Config.Midi.NoteOffset;
         watch.Restart();
         PlayNote(note);
     }
 }
Exemplo n.º 30
0
        //=========== HELPERS ============
        #region Helpers

        /**<summary>Checks if the path is valid.</summary>*/
        private bool ValidPathTest(bool checkExists = true)
        {
            if (LocalizationPacker.ExePath == "")
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "The Terraria path cannot be empty!", "Invalid Path");
                return(false);
            }
            try {
                if (!File.Exists(LocalizationPacker.ExePath) && checkExists)
                {
                    TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find Terraria executable!", "Missing Exe");
                    return(false);
                }
            }
            catch (ArgumentException) {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "You must enter a valid Terraria path!", "Invalid Path");
                return(false);
            }

            return(true);
        }