(01-19-2012, 07:13 AM)scummos Wrote: [ -> ]You aren't even initializing the pointer in the first patch. How should this work, then?
What are you trying to achieve, if I may ask? ;P
What do you mean I'm not initializing the pointer? Isn't this pointer initialization?
Code:
wxCheckBox* LoadFiles;
I'm not achieving anything specific, just learning.
In your first patch, you just write wxCheckBox* x;. This does, like, nothing; it just reserves some memory (sizeof(*wxCheckBox) bytes) which is filled with random garbage. If you do something like x->someMethod(), the program will crash. In your next post, you fixed this by assigning the pointer the address of a newly created wxCheckBox instance, thus it then worked.
I just wanted to tell you that what you first did could never possibly work, and why.
Oh, and for the code you quoted: No, this is *not* pointer initialization. If you wanted to initialize the pointer, you'd write something like
foo* bar = 0;
Then the pointer would point to the (invalid) address "0". You usually want it to point to an instance of an object instead; if you want to create one, do so:
foo* bar = new foo();
Be aware that this will only be deleted if you call "delete bar", otherwise it will be kept in memory until the program is terminated, wasting memory if it's not needed any more.
Woops, you're right. I wasn't paying close enough attention and that's why it was crashing.
(I love/hate pointers.)
I hate to double post, but no one's going to see this if I don't.
What's the best way to detect the presence of a file within one of Dolphin's directories? Is there a good function that I could use?
ifstream ifile(filename);
if (ifile) {
// The file exists, and is open for input
}
Sure, but how do I navigate to a specific directory, i.e. User/Load/Textures? Or is there a function that does it all?
(01-20-2012, 01:38 AM)dannzen Wrote: [ -> ]ifstream ifile(filename);
if (ifile) {
// The file exists, and is open for input
}
No.
Use FileUtil::Exists or something, instead.
(01-20-2012, 01:46 AM)HawaiianPunch Wrote: [ -> ]Sure, but how do I navigate to a specific directory, i.e. User/Load/Textures? Or is there a function that does it all?
File::GetUserPath(D_DUMPTEXTURES_IDX);
How's this function for finding if a file exists in the User/Load/Files directory? (Yes, LOAD_FILES_DIR is defined as Load/Files)
Code:
bool FileLoader::IsFilePresent(std::string input)
{
File::SetCurrentDir(USERDATA_DIR DIR_SEP LOAD_DIR);
File::CreateDir("Files");
File::SetCurrentDir(USERDATA_DIR DIR_SEP LOAD_FILES_DIR);
if(File::Exists(input))
{
return true;
}
return false;
}
Bad. You shouldn't change the current working directory just to create a directory. Use sth like File::CreateDir(File::GetUserPath(D_LOADFILES_IDX)) instead... and do that in DolphinWX/Src/Main.cpp where the other dirs get created as well (you'll obviously have to make GetUserPath recognize that definition first).
..