I have a program who's working directory is ~/Library/Application Support/MyApp, it looks here for the config.cfg and log files. The program needs a map file called MP512-Map.map. It looks in this directory to load it.
When the program is first run on a new machine its likely the file is not in this location, but on the users desktop or within the .dmg that the executable is distributed in. I want a file dialog to pop up and get the location of the .map file (if its not already present in the working directory) and then I want the program to copy the file from that location to the working directory so that next time the program is run the .map file can be loaded right away from there.
I have the following code:
QString path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
QString desktop = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(".");
}
QString MapPath = path+"/MP512-Map.map";
QFile file(MapPath);
QFile tempfile;
if(file.exists()!=true){
qDebug()<<"MAP FILE NOT FOUND.";
QString temppath = QFileDialog::getOpenFileName(this,tr("Find Location of MP512-Map file:"),desktop,tr("Map Files (*.map)"));
tempfile.copy(temppath,path);
qDebug() << "location" << temppath;
qDebug() << "destination: " << path;
}
After this the read in of the map file occurs. The issue is with the copy. The file does not successfully get copied over.
The console output is showing the correct directories:
location "/Users/Mitch/Desktop/MP512-Map.map"
destination: "/Users/Mitch/Library/Application Support/AFE-MP-512"
Am I implementing the copy function correctly?
Yes this function implementation is correct. But there is few moments
if(!QFile::copy(temppath, file.fileName()))
qDebug() << file.errorString();