/// <summary> /// Pause the utility and starts the BackgroundListener /// </summary> private void Pause() { isPaused = true; isRunning = false; HelperComponent.PrintColouredMessage("Paused application " + getName(), ConsoleColor.DarkYellow); HelperComponent.ShowBalloon(getName(), "Paused"); StartBackgroundListener(); }
/// <summary> /// Whether the software finds a connected XBOX controller or not /// </summary> /// <returns> /// True if it finds a connected controller /// </returns> private bool CheckControllerConnection() { if (controller.IsConnected) { return(true); } HelperComponent.PrintColouredMessage("Controller not found, please connect one", ConsoleColor.DarkRed); return(false); }
/// <summary> /// Resume the Paused utility if buttons (A + B + Y + X) are pressed toghether for at least 2 seconds /// </summary> private void Resume() { if (CheckControllerConnection()) { isPaused = false; isRunning = true; HelperComponent.PrintColouredMessage("Resumed utility " + getName(), ConsoleColor.DarkYellow); HelperComponent.ShowBalloon(getName(), "Resumed"); Start(); } }
/// <summary> /// Takes a string as parameter and returns it with the first capital letter /// </summary> /// <param name="word"></param> /// <returns></returns> private string SetFirstLetterToUpper(string word) { try { return(word = char.ToUpper(word[1]) + word.Substring(2)); } catch (Exception e) { HelperComponent.PrintColouredMessage(e.Message, ConsoleColor.Red); } return(word); }
/// <summary> /// Starts a lighter update that listens to Resume buttons combination /// </summary> private void StartBackgroundListener() { HelperComponent.PrintColouredMessage("...now listenint in background, hold (A + B + X + Y) to resume the utility", ConsoleColor.Yellow, false); while (isPaused) { controller.GetState(out controllerState); if (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A) && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B) && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.X) && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Y)) { Resume(); } System.Threading.Thread.Sleep(1000); } }
// TODO:Implement an overload constructor where the user can pass the chosen folder path /// <summary> /// Reorganizes your current Desktop by creating a new folder (If it doesn't already exists) for every /// different extension type that it finds. Then it moves the according files into the correct named foder. /// </summary> public void Start() { string currentFileName; string currentFileExtension; string destinationFolderPath; string destinationFilePath; startNotification(true); foreach (string filePath in desktopFilePaths) { try { currentFileName = Path.GetFileNameWithoutExtension(filePath); currentFileExtension = Path.GetExtension(filePath); destinationFolderPath = Path.Combine(desktopPath, SetFirstLetterToUpper(currentFileExtension)); if (!Directory.Exists(destinationFolderPath)) { Directory.CreateDirectory(destinationFolderPath); } destinationFilePath = Path.Combine(destinationFolderPath, Path.GetFileName(filePath)); File.Move(filePath, destinationFilePath); HelperComponent.PrintColouredMessage("Moving file to: " + destinationFilePath, ConsoleColor.Yellow); } catch (IOException e) { HelperComponent.PrintColouredMessage("IO Error: " + e.Message, ConsoleColor.Red); } catch (Exception e) { HelperComponent.PrintColouredMessage("General Error: " + e.Message, ConsoleColor.Red); } } Stop(); }
/// <summary> /// This is the controller main cycle /// </summary> public void Start() { try { isRunning = CheckControllerConnection(); if (isRunning) { startNotification(true); } while (isRunning) { Update(); System.Threading.Thread.Sleep(10); } } catch (SharpDX.SharpDXException e) { HelperComponent.PrintColouredMessage(e.Message, ConsoleColor.DarkRed); isRunning = false; } }