mercredi 29 avril 2015

Using Resource Files in a Release Build - Files don't seem to be recognized

I built a piece of software that ultimately parses text files and writes HTML documents with the information contained in said text files. The program works as expected in debug mode, but the release build doesn't seem to be able to read the files correctly.

The program contains a configuration file of sorts, and one of the values within it is a Boolean value that tells the system whether or not the user needs to set these config options. If they do not need to configure the system, the menu to do so is not presented; however, every time I run the release executable, it goes into that menu, and the config file is emptied (This I attribute to the fact that he is trying to write the new configuration settings to the file, but the point is that he shouldn't be getting here because the file held the value telling him to skip this process).

I've found that the system will read the file in fine, but only if you refresh the current explorer window before running the executable, and even then, this only works once. After that, the issue resurfaces.

I wondered initially if it was an issue with the location of the resource files to the executable and where they were placed during debugging, but I don't think that's the case since the release build is capable of loading the correct values at least once. I'm kind of at a loss for which direction to go in, I feel like it's a path or other build setting that is wrong, but I am not familiar with configuring those settings in visual studio 2013.

I am using std::ifstream and std::ofstream to read and write files, and assert that it's good() before proceeding in the code. All streams are closed at the end. I have posted code related to the part of the system dealing with the reading/writing of the config file below.


Writing:

 Initialization_Package Initialize(){
    //Declare Lexical Variables
    Initialization_Package toReturn;
    ofstream out;
    out.open("Control_SetupProfile.txt");

    cout << "Initializing. . ." << endl;
    cout << "We need some information..." << endl;

    cout << "How many rooms does your conference center have?" << endl;
    cout << "-->3 (System currently only supports 3 rooms)" << endl;
    toReturn.numOfRooms = 3;

    cout << "How many pairs of speakers do you stock? (Remember to exclude a few for"
        << "\nbackups): " << endl;
    cout << "-->";
    cin >> toReturn.speakersAvailable;

    cout << "How many white boards do you stock? (Remember to exclude a few for backups):"
        << endl;
    cout << "-->";
    cin >> toReturn.whiteBoardAvailable;

    cout << "How many microphones do you stock? (Remember to exclude a few for backups):"
        << endl;
    cout << "-->";
    cin >> toReturn.micsAvailable;

    cout << "How many projectors do you stock? (Remember to exclude a few for backups):" << endl;
    cout << "-->";
    cin >> toReturn.projectorAvailable;

    cout << "How many people fit into the smallest room?" << endl;
    cout << "-->";
    cin >> toReturn.seatsInRoosevelt;

    cout << "How many people fit into the medium sized room?" << endl;
    cout << "-->";
    cin >> toReturn.seatsInLincoln;

    cout << "How many people fit into the largest room?" << endl;
    cout << "-->";
    cin >> toReturn.seatsInWashington;

    cout << "Finishing..." << endl;
    if (out.is_open()){
        //Write the data
        out << toReturn.numOfRooms << endl;
        out << toReturn.speakersAvailable << endl;
        out << toReturn.whiteBoardAvailable << endl;
        out << toReturn.micsAvailable << endl;
        out << toReturn.projectorAvailable << endl;
        out << toReturn.seatsInRoosevelt << endl;
        out << toReturn.seatsInLincoln << endl;
        out << toReturn.seatsInWashington << endl;
        out << "true" << endl;
        //Append the MISC details of the database
        out << "#END FORMATTED DATA" << endl;
        out << "* | ===================================================================================== | *" << endl;
        out << "* | Database: Record                                                                      | *" << endl;
        out << "* | DBA : jadkin31@kent.edu                                                               | *" << endl;
        out << "* | Infrastructure Last Updated: 4/5/15                                                   | *" << endl;
        out << "* | Table: Control_SetupProfile                                                           | *" << endl;
        out << "* | ===================================================================================== | *" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "int" << endl;
        out << "bool" << endl;
        out << "\n*********************************************************************************************" << endl;
        out << "#Reset values(Requires initial setup again):" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0" << endl;
        out << "0";

        out.close();
    }
    else{
        cout << "Fatal error writing to database! - (Local Profile)\n";
    }

    return toReturn;
}

Reading:

void loadControl(bool& init, Initialization_Package& prev){
    //Declare Lexical Variables
    ifstream in;
    in.open("Control_SetupProfile.txt");

    if (in.is_open()){
        //Scan in the data
        in >> prev.numOfRooms;
        in >> prev.speakersAvailable;
        in >> prev.whiteBoardAvailable;
        in >> prev.micsAvailable;
        in >> prev.projectorAvailable;
        in >> prev.seatsInRoosevelt;
        in >> prev.seatsInLincoln;
        in >> prev.seatsInWashington;
        in >> init;

        in.close();
    }
    else{
        cout << "Fatal error connecting to database! - (Local Profile)\n";
    }
}

The debug executable is located in C:\Users\Jake\documents\visual studio 2013\Projects\UCCS\Debug\UCCS.exe and it is reading and writing from/to C:\Users\Jake\Documents\Visual Studio 2013\Projects\UCCS\UCCS (Probably because they are resource files) and I tried placing the build release in the same folder as the debug release, but he is still just creating (and I'm assuming reading) the files in the local (current) directory. Can any one hint at what might be happening?

Edit: I've never had this issue before; however, this is the first time I've ever added the files to Visual Studio, I typically just run the debug executable manually after building it with VS keeping the files in the debug directory.

Aucun commentaire:

Enregistrer un commentaire