Timer Console
Loading...
Searching...
No Matches
files.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 Ryan Large
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef FILES_H
26#define FILES_H
27
28#include <iostream>
29#include <fstream>
30#include <filesystem>
31#include <map>
32#include "../Alarm/alarm.h"
33#include "../Timer/timer.h"
34#include "../Timer/timerData.h"
36
37#ifdef _WIN32
38#include <windows.h>
39#include <shlobj.h>
40#endif
41
45class Files {
46 public:
50 Files();
51
52 // Timer Methods
58 std::vector < TimerData > getTimers();
59 void saveTimers(const std::vector < TimerData>& times);
60
61 // Alarm Methods
67 std::vector < AlarmData > getAlarms();
68
69 protected:
74 std::string getAppDataPath() {
75 #ifdef _WIN32
76 char path[MAX_PATH];
77 if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, path))) {
78 return std::string(path) + "\\timer-console\\";
79 }
80 #else
81 const char* homeDir = getenv("HOME");
82 if (!homeDir) {
83 homeDir = "";
84 }
85 return std::string(homeDir) + "/.timer-console/";
86 #endif
87 return "";
88 }
89
95 nlohmann::json deserializeJson(std::ifstream& inFile);
96
102 void saveJsonToFile(const std::string& fileName, json j);
103
104 private:
105};
106
107#endif
void saveTimers(const std::vector< TimerData > &times)
Definition files.cpp:177
std::string getAppDataPath()
getAppDataPath returns the string that represents the file path which locates the configuration direc...
Definition files.h:74
Files()
Files constructor takes in no parameters and executes no initializing logic.
Definition files.cpp:39
std::vector< TimerData > getTimers()
getTimers takes in no parameters. This method is made to fetch timers stored from a configuration fil...
Definition files.cpp:117
std::vector< AlarmData > getAlarms()
getAlarms takes in no parameters. This method is made to fetch alarms from a configuration file which...
Definition files.cpp:42
void saveJsonToFile(const std::string &fileName, json j)
saveJsonToFile does as it says. It takes any json shape and saves it to a file found or created at th...
Definition files.cpp:236
nlohmann::json deserializeJson(std::ifstream &inFile)
deserializeJson returns a valid JSON object
Definition files.cpp:208
nlohmann::json json
For better readability and development process using json is declared here at the top of the implemen...
Definition files.cpp:37