Crate rl_hours_tracker

source
Expand description

§Rocket League Hours Tracker

This was made specifically for the Epic Games version of Rocket League as the Epic Games launcher has no way of showing the past two hours played in the same way that steam is able to.

However, this program can and should still work with the steam version of the game.

It is HIGHLY recommended to not manually alter the files that are created by this program otherwise it could lead to unwanted behaviour by the program

    println!("You got it Oneil :)");

§Library

The Rocket League Hours Tracker library contains modules which provide additional functionality to the Rocket League Hours Tracker binary. This library is currently implements the website_files module, which provides the functionality to generate the Html, CSS, and JavaScript for the Rocket League Hours Tracker website.

The website functionality takes adavantage of the build_html library, which allows us to generate the Html for the website, alongside the webbrowser library, which allows us to open the website in a browser.

§Use Case

Within the website_files module, there is a public function website_files::generate_website_files, which writes the files for the website in the website directory in RlHoursFolder. This function accepts a bool value, which determines whether the option to open the website in a browser should appear when this function is called.

use rl_hours_tracker::website_files;

// This will generate the website files and prompt you with the option to open the
// webstie in a browser.
website_files::generate_website_files(true);

// This will also generate the website but will not prompt the user to open the website
// in a browser.
website_files::generate_website_files(false);

Modules§

  • This module contains the functionality to generate the Html, CSS, and JavaScript for the Rocket League Hours Tracker website.

Structs§

Functions§

  • This function calculates the hours recorded in the past two weeks and returns the total number of seconds as u64 The contents from date.txt are read and split by \n character and stored in a Vec<&str> Vector. It is then ordered and looped through in order to compare the date to the current iteration of the date two weeks ago. The seconds are retrieved from the dates that match the current date in the iteration of the while loop and the seconds are added to seconds_past_two which is returned as an Result<u64> at the end of the function.
  • This function takes a reference of a Vec<&str> Vector and returns a usize as an index of the closest after the date two weeks ago.
  • This function creates the directories for the program. It creates a local Vec<Result> which stores fs::create_dir results.
  • This function is used to perform a binary search on a Vec<&str> Vector and compares the dates in the Vector with the c_date String. The function then returns a usize for the index of the date, or a usize::MAX if the date is not present.
  • This function runs the program
  • This function updates the hours in the past two weeks in the hours.txt file. The hours past two is calculated through the calculate_past_two function The function returns a Result<bool> if the function was able to successfully update the hours past two, and write it to the hours.txt file.
  • This function writes new contents to the date.txt file. This uses the Local struct which allows us to use the Local::now() function to retrieve the local date and time as DateTime<Local>. The date is then turned into a NaiveDate by using DateTime<Local>::date_naive() which returns us the date by itself.
  • This function writes the new contents to the hours.txt file. This includes the total seconds, hours, and hours_past_two. This function then returns a [Result<()>] when file operations were all successful.