• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Manhattanisgr8

Need help with installation of program

4 posts in this topic

I have created a simple console application that allows a user to manage a product inventory. After the user quits, it saves the data into a txt file. When the user opens the application again, it reads the information from the text file. I am using Inno to "distribute" the application. My question is, the program works, however, after installing it, it doesn't create the txt file, thus it can't read from it. Could this be a simple path finding problem? If so, how can I fix this? Below is the code in question:

side note: this is an application I developed but have to write a manual for it for my technical writing class. Thus, the reason for using Inno.

// File Name: ProductInventory.cpp
//
// Author: Travis Alt
// Date: 3/31/2014
// Assignment Number: 5
// CS 2308.256 Spring 2014
// Instructor: Jill Seaman
//
// An object that holds an array of Products. You can
// add or remove a product, sort the array by product name,
// get the total quantity in the inventory, or display the
// inventory in a table format.

#include <iostream>
#include <fstream>
#include "ProductInventory.h"

using namespace std;

ProductInventory::ProductInventory()
{
	count = 0;
	capacity = 0;

	ifstream inFile;
	inFile.open("inventory.txt");

	if (inFile.is_open())
	{
		Product product;
		string productName, locator;
		int quantity;
		double price;

		while (getline(inFile, productName))
		{
			//getline(inFile, productName);
			inFile >> locator;
			inFile >> quantity;
			inFile >> price;

			product.setProductName(productName);
			product.setLocator(locator);
			product.setQuantity(quantity);
			product.setPrice(price);
			inFile.ignore(50, '\n');

			addProduct(product);
		}
	}
	else
	{
		inFile.close();
		ofstream outFile;
		outFile.open("inventory.txt");
		outFile.close();
	}
}

//***********************************************************
// ProductInventory: constructor of the product inventory
//
// size: size of the array
// returns nothing
//***********************************************************
ProductInventory::ProductInventory(int size)
{
	//inventory = new vector<Product>;
	count = 0;
	capacity = size;

	ifstream inFile;
	inFile.open("inventory.txt");

	if (inFile.is_open())
	{
		Product product;
		string productName, locator;
		int quantity;
		double price;

		while ((inFile.peek() != '\n') && (getline(inFile, productName)))
		//while (getline(inFile, productName))
		{
			inFile >> locator;
			inFile >> quantity;
			inFile >> price;

			product.setProductName(productName);
			product.setLocator(locator);
			product.setQuantity(quantity);
			product.setPrice(price);

			addProduct(product);
		}
	}
	else
	{
		inFile.close();
		ofstream outFile;
		outFile.open("inventory.txt");
		outFile.close();
	}
}

//***********************************************************
// addProduct: adds a new product to the array. If the array is full
// it calls resize to double the size of the array.
//
// product: the product to be added
// returns false if there is a product with the same name and location,
// otherwise returns true if the product was added
//***********************************************************
bool ProductInventory::addProduct(Product product)
{
	/*if (count == capacity)
	{
		resize();
	}*/
	for (int x = 0; x < count; x++)
	{
		if (inventory[x].getProductName() == product.getProductName() &&
			inventory[x].getLocator() == product.getLocator())
		{
			return false;
		}

	}
	inventory.push_back(product);
	sortInventory();
	writeToFile();
	count++;
	return true;
}

//***********************************************************
// removeProduct: removes the product from the list by hiding it
// at the end of the array until it is replaced by another product
//
// productName: name of the product to be removed
// locator: the location of the product to be removed
// return true if the product was removed, else return false if it
// can't find the product and location.
//***********************************************************
bool ProductInventory::removeProduct(Product product)
{
	int index = 0; // index of where the product is in the array
	for (int x = 0; x < count; x++)
	{
		if (product.getProductName() == inventory[x].getProductName() && product.getLocator() == inventory[x].getLocator())
		{
			index = x;

			inventory.erase(inventory.begin() + index);
			count--;
			return true;
		}
	}
	return false;
}

//***********************************************************
// showInventory: displays the current inventory in the form of
// a table
//
// returns void
//***********************************************************
void ProductInventory::showInventory()
{
	sortInventory();

	cout << "\nLocation	Quantity	Price	        Name" << endl;
	cout << "--------------------------------------------------------------------------" << endl;

	for (int x = 0; x < count; x++)
	{
		cout << inventory[x].getLocator() << "\t\t";
		cout << inventory[x].getQuantity() << "\t\t";
		cout << inventory[x].getPrice() << "\t\t";
		cout << inventory[x].getProductName() << endl;
	}
}

//***********************************************************
// getTotalQuantity: adds up the quantity of each product in the array
//
// returns total number of products in the array
//***********************************************************
int ProductInventory::getTotalQuantity()
{
	int totalQuantity = 0; // initial size of the total quantity

	for (int x = 0; x < count; x++)
	{
		totalQuantity += inventory[x].getQuantity();
	}
	return totalQuantity;
}

//***********************************************************
// sortInventory: reorders the array by name from A-Z
//
// returns void
//***********************************************************
void ProductInventory::sortInventory()
{
	for (int i = 0; i < count - 1; i++)
	{
		for (int x = 0; x < count - 1; x++)
		{
			if (inventory[x] > inventory[x + 1])
			{
				Product temp = inventory[x + 1];
				inventory[x + 1] = inventory[x];
				inventory[x] = temp;
			}
			else
			{
				continue;
			}
		}
	}
}

//***********************************************************
// resize: doubles the current size of the array if there is
// not enough space to add more products
//
// returns void
//***********************************************************
void ProductInventory::resize()
{
	int newSize = capacity * 2;

	Product *newInventory = new Product[newSize];

	for (int x = 0; x < count; x++)
	{
		newInventory[x] = inventory[x];
	}

	capacity = newSize;
	//delete[] inventory;
	//inventory = newInventory;
}

void ProductInventory::writeToFile()
{
	ofstream outFile;

	outFile.open("inventory.txt");

	for (int x = 0; x < count; x++)
	{
		outFile << inventory[x].getProductName() << endl << inventory[x].getLocator() << endl << inventory[x].getQuantity() << endl << inventory[x].getPrice() << endl;
	}

	outFile.close();

	outFile.open("inventory_print.txt");

	outFile << "Location	Quantity	Price	        Name" << endl;
	outFile << "--------------------------------------------------------------------------" << endl;

	for (int x = 0; x < inventory.size(); x++)
	{
		outFile << inventory[x].getLocator() << "\t";
		outFile << inventory[x].getQuantity() << "\t\t";
		outFile << inventory[x].getPrice() << "\t\t";
		outFile << inventory[x].getProductName() << endl;
	}
	outFile.close();
}

bool ProductInventory::adjustQuantity(Product product)
{
	for (int x = 0; x < inventory.size(); x++)
	{
		if (inventory[x].getProductName() == product.getProductName() && inventory[x].getLocator() == product.getLocator())
		{
			inventory[x].setQuantity(product.getQuantity());
			return true;
		}
		else
			return false;
	}

	return false;
}

bool ProductInventory::adjustPrice(Product product)
{
	for (int x = 0; x < inventory.size(); x++)
	{
		if (inventory[x].getProductName() == product.getProductName() && inventory[x].getLocator() == product.getLocator())
		{
			inventory[x].setPrice(product.getPrice());
			return true;
		}
		else
			return false;
	}

	return false;
}

double ProductInventory::getTotalPrice()
{
	double totalPrice = 0.0;

	for (int x = 0; x < inventory.size(); x++)
	{
		totalPrice += inventory[x].getPrice();
	}

	return totalPrice;
}
0

Share this post


Link to post
Share on other sites
Where does it get installed? How are you invoking the program? Do you know the working directory of the program when it is running? Does it work if you start the program, perhaps via the command line, from a location such as your home directory?

Installing programs often places them in security privileged locations that are shared between users. For security purposes, and to prevent unexpected issues with multi-user systems, programs are typically not allowed to write files in the same location they are installed.

User data should be stored in the users home directory somewhere. Different platforms have different conventions. An alternative is to allow the user to specify the location of the database, perhaps as a command line parameter.
2

Share this post


Link to post
Share on other sites

I didn't even think about the permissions. I was having the installer put it into the program files folder in the windows directory. Could I perhaps have the program write to the public folder in users? If so would the following statement be correct?:

outFile.open("C:\\Users\\Public\\Documents\\ProductManager\\inventory.txt");
0

Share this post


Link to post
Share on other sites

Forgot to mention that I am targeting Windows users. In the manual, I am going to instruct the users how to use it in Linux via makefile due to the lack of information I was finding on the internet for packaging distros.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0