You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4.2 KiB

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 Shutdown Timer folder, so all paths to files I mention will be relative to this folder. The Windows Application Packaging and Windows Installer Packaging folders contain packaging projects for generating an install file and uploading the packaged project to the Microsoft Store. Icon and Screenshots only contain the project's icon and screenshots for the README.

How to get started

I'd recommend using Visual Studio 2019 Community as it's the IDE I use for developing the project. You can simply open the ShutdownTimerClassic.sln solution file in the root folder and it will load the entire project including packaging projects and get everything set up.

Application Structure 🕸

The application's entry point is Program.cs which just registers Helpers/ExceptionHandler.cs to catch unhandled or thread exceptions and then launches an instance of Menu.cs.

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.

Helpers 🧱

Helpers/ExceptionHandler.cs will gather information about the system and the application and generated a log file which 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/Numerics.cs includes a few numerical functions which validate and process the 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.

Dependencies 📚

This app depends on Microsoft.Windows.SDK.Contracts for interacting with newer Windows API's which are otherwise only available to UWP apps and 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.