Skip to content

Latest commit

 

History

History
67 lines (36 loc) · 4.99 KB

Structure.md

File metadata and controls

67 lines (36 loc) · 4.99 KB

Structure & Design 🗂

Details on how the project is organized and how the different classes interact with each other.

This project is relatively simple. The actual codebase is within the src/ShutdownTimer folder, so all paths to files I mention will be relative to this folder. The src/WindowsApplicationPackaging and src/WindowsInstallerPackaging folders contain packaging projects for generating an install file and uploading the packaged project to the Microsoft Store. media/icon and media/screenshots only contain the project's icon and screenshots for the README.

How to get started ⚡

I'd recommend using Visual Studio Community 2022 as it's the IDE I use for developing the project. You can simply open the ShutdownTimerClassic.sln solution file in the src/ directory and it will load the entire project including packaging projects and get everything set up. If you get an error about the WindowsInstallerPackaging being incompatible, you are missing the VS Installer Projects Extension.

Application Structure 🕸

The application's entry point is Program.cs which initializes the settings, applies CLI arguments using ArgProcessor.cs, and registers Helpers/ExceptionHandler.cs to catch unhandled or thread exceptions and then launches an instance of Menu.cs (or Countdown.cs in case the CLI args request it).

Forms 🎨

Forms are the graphical windows you see and interact with. This app has three of them.

Each form (Form.cs) will also have a Form.Designer.cs and Form.resx file. These files control the visual design of the form and contain metadata for the Visual Studio Designer. As you probably guessed, they are generated by the Visual Studio Designer and should not be edited by a text editor as manual editing may break the Designer. Only Form.cs holds the actual code (logic) for the respective form.

Menu.cs is the starting form that holds all the controls for the timer and the start button. It uses Helpers/Numerics.cs to validate and calculate the time for the countdown. Upon clicking start it will create and show an instance of Countdown.cs.

Countdown.cs manages the countdown timer and tray icon. It will call Helpers/ExitWindows.cs when the timer reaches zero and uses Helpers/ExecutionState.cs to keep the system awake during the countdown.

Settings.cs manages the settings and shows information about the application. It can be reached by clicking the button with the cog icon in the upper right-hand corner of Menu.cs. It gets and sets the settings with Helpers/Settings.cs.

InputBox.cs is a dialog intended to ask the user for a text-based input. It's invoked by other forms only.

Helpers 🧱

Helpers/ApplicationInstanceManager.cs contains the logic for detecting multiple instances of the application.

Helpers/ArgProcessor.cs is responsible for reading CLI arguments and is only used by Program.cs

Helpers/ExceptionHandler.cs will gather information about the system and the application and generates a log file that it places on the user's desktop and informs them about the exception. This replaces the default .NET exception handler. It's turned off in debugging mode.

Helpers/ExecutionState.cs keeps the system awake during the countdown.

Helpers/ExitWindows.cs calls the respective Windows APIs for the chosen power action.

Helpers/Format.cs contains string formatting functions.

Helpers/Time.cs contains the core functions to process and evaluate time data.

Helpers/Settings.cs loads and saves the settings to a settings.json file in the user's application data folder. It exposes a Settings property to the entire application which is used to get and set the desired settings. Pretty much every form uses this. The settings do need to be saved to the settings.json file before exiting the application otherwise all changes would be lost. Menu.cs and Settings.cs do this before exiting.

Helpers/WindowsAPIs.cs contains logic regarding APIs provided by Windows (excluding the ones required for executing power actions, which are handled by ExitWindows.cs).

Dependencies 📚

This app depends on Newtonsoft.Json for serializing/deserializing the settings to and from the settings.json file.

Other files and folders 👾

Icons/ contains the application's icons used for compiling and packaging the application.

Properties/ contains application metadata and assembly info.

Resources/ contains application resources like icons used inside the application.

App.config and app.manifest contain application metadata, capabilities, features, and configuration stuff needed for compiling and running the app.

Shutdown Timer.csproj is the C# project file that contains project and app metadata, configuration parameters, and defines the project's entry point as well as forms, classes, and dependencies used in the project.