mirror of https://github.com/PatrickLipka/tt.git
Added month string to the tracking file data and leagcy mode for old files
This commit is contained in:
parent
7d303d5931
commit
5098dc0357
|
@ -94,6 +94,9 @@ void ProjectList::save(std::string file_name){
|
||||||
if (!of){
|
if (!of){
|
||||||
std::cout << "Could not open file " << file_name << " for writing!" << std::endl;
|
std::cout << "Could not open file " << file_name << " for writing!" << std::endl;
|
||||||
}
|
}
|
||||||
|
size_t month_len = month.length();
|
||||||
|
of.write((char*) &month_len, sizeof(size_t));
|
||||||
|
of.write((char*) month.c_str(), month_len);
|
||||||
of.write((char*) &num_projects, sizeof(int));
|
of.write((char*) &num_projects, sizeof(int));
|
||||||
of.write((char*) &active_project_id, sizeof(int));
|
of.write((char*) &active_project_id, sizeof(int));
|
||||||
for (int i=0; i<num_projects; i++){
|
for (int i=0; i<num_projects; i++){
|
||||||
|
@ -113,12 +116,24 @@ void ProjectList::save(std::string file_name){
|
||||||
}
|
}
|
||||||
|
|
||||||
// reads project list from binary file
|
// reads project list from binary file
|
||||||
void ProjectList::load(std::string file_name, bool ignore_worktimes){
|
void ProjectList::load(std::string file_name, bool ignore_worktimes, bool legacy_mode){
|
||||||
std::ifstream inf(file_name, std::ios::binary);
|
std::ifstream inf(file_name, std::ios::binary);
|
||||||
int active;
|
int active;
|
||||||
if (!inf){
|
if (!inf){
|
||||||
std::cout << "Could not open file " << file_name << " for reading!" << std::endl;
|
std::cout << "Could not open file " << file_name << " for reading!" << std::endl;
|
||||||
}
|
}
|
||||||
|
size_t month_len;
|
||||||
|
|
||||||
|
if (!legacy_mode){
|
||||||
|
// read month string from file
|
||||||
|
inf.read((char*) &month_len,sizeof(size_t));
|
||||||
|
char *month_tmp = new char[month_len+1];
|
||||||
|
inf.read(month_tmp,month_len);
|
||||||
|
month_tmp[month_len] = '\0';
|
||||||
|
month = month_tmp;
|
||||||
|
delete [] month_tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inf.read((char*) &num_projects,sizeof(int));
|
inf.read((char*) &num_projects,sizeof(int));
|
||||||
// save copy of num_projects to control loop and apply later as
|
// save copy of num_projects to control loop and apply later as
|
||||||
// num_projects will get bigger when adding projects to the project list
|
// num_projects will get bigger when adding projects to the project list
|
||||||
|
|
|
@ -33,7 +33,7 @@ class ProjectList{
|
||||||
Project *active_project;
|
Project *active_project;
|
||||||
void set_active_project(int id);
|
void set_active_project(int id);
|
||||||
void save(std::string file_name);
|
void save(std::string file_name);
|
||||||
void load(std::string file_name, bool ignore_worktimes=false);
|
void load(std::string file_name, bool ignore_worktimes=false, bool legacy_mode=false);
|
||||||
Project *find_project_by_name(std::string proj_name);
|
Project *find_project_by_name(std::string proj_name);
|
||||||
int find_project_id_by_name(std::string proj_name);
|
int find_project_id_by_name(std::string proj_name);
|
||||||
};
|
};
|
||||||
|
|
13
src/ui.cpp
13
src/ui.cpp
|
@ -588,7 +588,17 @@ void command_report(std::string date_str, ProjectList* proj_list){
|
||||||
}else{
|
}else{
|
||||||
ProjectList list(month);
|
ProjectList list(month);
|
||||||
std::string file_name = tracking_dir+"/"+date_str;
|
std::string file_name = tracking_dir+"/"+date_str;
|
||||||
|
// legacy support for old tracking file format prior to version 1.3.0
|
||||||
|
// to be dropped with next major release
|
||||||
|
if (std::stoi(year) <= 2022 && std::stoi(month) <= 4){
|
||||||
|
std::cout << "Warning: possibly reading old data file of tt v.<1.3.0." << std::endl;
|
||||||
|
std::cout << "Support for these files will be dropped with the next major release!" << std::endl;
|
||||||
|
std::cout << "Consider convertig them using the convert command." << std::endl << std::endl;
|
||||||
|
list.load(file_name,false, true);
|
||||||
|
}else{
|
||||||
list.load(file_name);
|
list.load(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
if (list.num_projects > 0){
|
if (list.num_projects > 0){
|
||||||
std::cout << "Report for " << user_name << ", month: " << date_str << std::endl << std::endl;
|
std::cout << "Report for " << user_name << ", month: " << date_str << std::endl << std::endl;
|
||||||
for (int i=0; i<list.num_projects; i++){
|
for (int i=0; i<list.num_projects; i++){
|
||||||
|
@ -614,8 +624,7 @@ void command_report(std::string date_str, ProjectList* proj_list){
|
||||||
// save project list to file, uses system("mkdir") to create diretory
|
// save project list to file, uses system("mkdir") to create diretory
|
||||||
// might be replaced by C++ filesystem API int the future
|
// might be replaced by C++ filesystem API int the future
|
||||||
void command_save(ProjectList *proj_list){
|
void command_save(ProjectList *proj_list){
|
||||||
std::string date_str = get_date();
|
std::string file_name = tracking_dir+"/"+proj_list->month;
|
||||||
std::string file_name = tracking_dir+"/"+date_str;
|
|
||||||
std::string command = "mkdir -p "+tracking_dir;
|
std::string command = "mkdir -p "+tracking_dir;
|
||||||
system (command.c_str());
|
system (command.c_str());
|
||||||
proj_list->save(file_name);
|
proj_list->save(file_name);
|
||||||
|
|
Loading…
Reference in New Issue