#ifndef OPEN_SAVE_H_INCLUDED #define OPEN_SAVE_H_INCLUDED ///LIBRARIES #include #include #include #include #include #include #include #include #include #include "drawing_components.h" #include "stare_table.h" //Tudor ILADE toate functiile ///Functie responsabila de crearea fisierului de proiect in directorul Projects char* path_for_projects_directory(int type=0) { //se creaza path-ul catre directorul unde vor fi salvate proiectele char cwd[256]; getcwd(cwd, 256); char* dir = new char[40]; char* path = new char[strlen(cwd)+12+strlen(dir)]; *path = '\0'; *dir = '\0'; strcat(dir, "Projects"); strcat(path, cwd); if(type==1) return path; strcat(path,"\\"); strcat(path,dir); //Se verifica existenta directorului pentru proiecte bool isDir = false; struct stat info; if(stat(path,&info)!=0) isDir = false; else if(info.st_mode & S_IFDIR) isDir = true; if(isDir==0) { //Directorul nu exista, deci int check = mkdir(path); if(!check) { return path; } } else { //Directorul exista, deci returnam path-ul return path; } } ///Functie responsabila de crearea unui proiect care returneaza path-ul catre fisier ul unde se va salva proiectul SITUATIA_TABLEI create_project(SITUATIA_TABLEI tabla,char* file_name) { char* path_to_file = new char[strlen(path_for_projects_directory())+strlen(file_name)+5]; path_to_file = path_for_projects_directory(); strcpy(tabla.path_to_dir,path_to_file); strcat(path_to_file, "\\"); strcat(path_to_file, file_name); strcat(path_to_file, "\.AT"); strcpy(tabla.path_file,path_to_file); FILE* project; project = fopen(path_to_file, "wb+"); if(project==NULL) { exit(1); tabla.ans=-1; return tabla; } char header[2] = {'A', 'T'}; fwrite(&header, sizeof(header),1,project); fclose(project); return tabla; } ///Functie responsabila de salvarea tablei actuale in proiectul deschis. (se va folosi si pentru save as) int save_project(SITUATIA_TABLEI &table, char* path) { FILE* project; project = fopen(path, "wb+"); if(project == NULL) { return -1; } char header[2] = {'A', 'T'}; fwrite(&header, sizeof(header),1,project); if(table.v.size()!=0) { for(int i=0; iPAIR; PAIR.first = cmp.legatura[2*i]; PAIR.second = cmp.legatura[2*i+1]; cmp_table.legatura.push_back(PAIR); } tabla.v.push_back(cmp_table); } for(int i =0; i