Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read

WON'T YOU JOIN US?
You are not a registered member and
are viewing this site as a guest.
Registration is simple and FREE.
Join this CrowdGather community today.
Registration offers the following perks:

» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging

join

Reply
 
Thread Tools Display Modes
Old March 3rd, 2013, 16:00   #1
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
Loading files filtered by extension

I am in need of a bit of advice and/or guidance. My google searches thus far have been fruitless, pointing only to C# tutorials of an excessively complicated nature.

I have an executable, and that executable loads a .png file on start up. That file is loaded by a specific name, and has to be in the executables directory.

What I would like to do is scan the exe's directory on init, looking for any .png files. Load the first one found by default, and allow for 'flipping' through all the .pngs in the directory.

I am using C++ with the SDL library.

Suggestions, pointers, advice, links?
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old March 3rd, 2013, 22:16   #2
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
GetModuleFileName and random shell functions to get the path out of it, then FindFirstFile/FindNextFile
same with opendir for unix
or boost's filesystem for possibly both
-Ashe- is offline   Reply With Quote
Old March 3rd, 2013, 22:24   #3
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
Quote:
Originally Posted by TastEPlasma View Post
...pointing only to C# tutorials of an excessively complicated nature.
Complicated nature???? doing such a Job in C# is ridiculously easy in comparison to the C++ conterpart. You either found wrong tutorials or the author of those were morons such a Job in C# takes around 1 line of code or 2 if you want it to look better


UPDATE:

I helped Omegadox a while back to do something like that in C# and all required is this:

Code:
string[] filters = new string[] {".z64", ".n64", ".v64", ".zip"};
var files Directory.GetFiles(dirpath, "*.*", SearchOption.AllDirectories).Where(u => filters.Contains(Path.GetExtension(u.ToLower()))).ToList());
In your case would be this only:
Code:
var files = Directory.GetFiles(Environment.CurrentDirectory, "*.png", SearchOption.AllDirectories);
this is just to Show you that i wasn't exagerating when i said that you actually can achieve that in 1 line of code

Here the reference Posts(check post #202 and #203)
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; March 5th, 2013 at 21:00..
@ruantec is offline   Reply With Quote
Old March 4th, 2013, 00:29   #4
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
Yea, regarding the c# stuff I found, more like 20-30 lines of codes that recourse through directories and sub-directories and lots of other things that are worthless to me.

Regardless, I am using c++, not c#. I have heard quite a bit of mixed opinions regarding c#.

Thanks for the suggestions guys, gives me a starting point to do some research, learn, and create. :-)
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote
Old March 4th, 2013, 01:10   #5
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
Quote:
Originally Posted by TastEPlasma View Post
Yea, regarding the c# stuff I found, more like 20-30 lines of codes that recourse through directories and sub-directories and lots of other things that are worthless to me.

Regardless, I am using c++, not c#. I have heard quite a bit of mixed opinions regarding c#.

Thanks for the suggestions guys, gives me a starting point to do some research, learn, and create. :-)
I know you're using C++, i was just pointing out your comment about the C# tutorials you found on the web and wanted to basically explain you what you just posted now.... Yes, there are tons of mixed opinions regarding C# but the main Problem with all that and the reason why i Keep sort of defending C# here is because those mixed opinions are mostly based in false or old Information. It's fine when someone write his opinion about something but first we should understand a language and then talk... sadly most People on the web don't do that.

Basically C# is the closest language to C++ and while C++ is powerful in many Areas C# is far better in others. I could start a rant over C++ annoyances and a huge post about it's awesomeness but that doesn't make the language worst or better. The same goes for C#... it has some annoyances but is incredibly powerful when used propertly and in most cases unlike C++ it saves you a lot of time and annoyances of the language itself.

Again... not many People actually care to properly learn C# and those are the first ones to start writing how bad the language is. For instance let's say you are a advanced C++ coder and tried C# based on those horribly made tutorials... it's very understanable that you will get annoyed by seeing a solution where you have to write 20-30 lines of codes just to accomplish a very Basic Task... now imagine you start ranting about how bad the language is and never realize that you just got it wrong and that such a solution was as simple as the one i wrote on my post(hope you get the Point).

Some are concern about Speeds and at a very few Areas they are right. However when done propertly you can get amazing Speeds and achieve similar or same results as C++ using far less code and spending far less time.

Here a very small example of an application i wrote in pure C#:


If a beginner write such a application the result would probably be a stuttering, resource hungry application that probably doesn't work at all since i'm pushing Frames myself on that Special case. The main difference between C++ and C# is that a beginner would be easily able to achieve that even getting bad results at the end while in C++ the same Person won't probably pass the hello world level.

I'm not saying by any means that C++ is bad as that would be a lie nor trying to make you Switch from C++ to C# as that is not my goal but saying that you shouldn't listen to all the misinformation being spread this days and try to find out things by yourself
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; March 4th, 2013 at 01:36..
@ruantec is offline   Reply With Quote
Old March 4th, 2013, 01:59   #6
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
Hmm, fair enough. I'll not write off c# just yet. If the advice of several indie devs is any clue, saving time and effort to produce the identical result is the best sort of optimization.

I have been listening to a lot of advice lately, think I will condense my thoughts into a blog post here in a few days to get it all summarized and recorded.

Again, thanks for the help. :-)
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote
Old March 5th, 2013, 01:26   #7
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
Ok, still researching but, I have found 3 possible ways to achieve this:

1. windows.h
2. boostfilesystem
3. dirent.h

Boost seems like the most noob-friendly once installed, but I can't use it since it is incompatible with minGW, which is the compiler I am using.

Since my compiler isn't POSIX compatible anyways, seems like the windows functions are the best choice. However, the windows examples (and particularly the microsoft webstie) seem excessively complicated to me. They don't seem concerned with catering to the noobs.

Dirent.h I dont know much about because I was going to use boost, then windows.

More and more learning, la de da. Maybe time for a beer and some virtual violence. ;-)

EDIT: I just noticed that I have ended every post with a non-forum smiley. Except not anymore, this one ends in an edit! *resists urge to place smiley here*
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote
Old March 5th, 2013, 05:59   #8
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
Ugh, so tired. Here is what I have so far:

Code:
std::string openfiles()
{
    std::string imagefiles;
    LPCTSTR lpFileName = "*.png";
    LPWIN32_FIND_DATA lpFindFileData = NULL;
    FindFirstFile(lpFileName, lpFindFileData);
    imagefiles = lpFindFileData->cFileName;
    return imagefiles;
}

//somewhere else
case SDLK_TAB: tiles = load_image(openfiles());
Compiles, but on pressing TAB crashes out and returns an error. Too tired to think anymore.

Oh, I realize this wont find subsequent files, but figured I should try to just get it working with a single file first.

...

Just noticed a serious bug in the reloading image function, fixed, re-upping now.
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote
Old March 15th, 2013, 06:00   #9
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
Bloody hell, finally got something working.

Using dirent.h:

Code:
int directoryloader()
{
    DIR *pngdir = NULL;
    pngdir = opendir(".");
    struct dirent *pent = NULL;
    std::string extension = ".png";

    while (pent = read//////////dir(pngdir))
    {
        imagefiles[filecounter] = pent->d_name;

        if (imagefiles[filecounter].find(extension, (imagefiles[filecounter].length() - extension.length())) != std::string::npos)
        {
            filecounter ++;
        }
        else
        {
            imagefiles[filecounter] = "";
        }
    }
    closedir(pngdir);
    return (filecounter-1);
}
Had to add the backslashes in the read////dir, because it was forbidding me to post it otherwise. *shrug*

Loads all the files with ".png" extension up in an array of strings, and returns the number of elements of the array that have data in them.

Don't have it fully implemented in ATV yet, but after it is and another feature I just thought of I will update it on my webpage.

Yay for small victories!
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote
Old March 15th, 2013, 11:45   #10
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
Almost forgot this thread, glad you got some results Anyways why are sou returning the amount of files found only??? you could instead use a std::vector<string> and pack the files in it then return the pointer. With that you can use the iterator to loop through it and get the size of it anytime if you need the count. It's better than using a global member like "imagefiles"
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; March 15th, 2013 at 11:52..
@ruantec is offline   Reply With Quote
Old March 15th, 2013, 14:04   #11
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
(quick note: having a local vector and returning a pointer to it is a really really really bad idea, might want to pass it in via a reference)
-Ashe- is offline   Reply With Quote
Old March 15th, 2013, 14:45   #12
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
Yeah, the idea is not to teach him better or super advanced ways but more that he get the idea and slowly improve itself. Just picking won't help him as he may not understand most of what we are trying to show him at the end and won't help him at all but looking for probably bad yet easy to understand ideas could have better results
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6
@ruantec is offline   Reply With Quote
Old March 15th, 2013, 18:52   #13
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
Telling him not to do something that's wrong and will crash is not really picking, otherwise he already got all his answers in the first reply
-Ashe- is offline   Reply With Quote
Old March 15th, 2013, 19:22   #14
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
Indeed but he didn't understood a bit hence why i was trying to look for simplier ways so that he can get the idea. Also i always choose pointers over references to implement algorithms and data structures but i agree that returning references is the better way
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; March 15th, 2013 at 19:38..
@ruantec is offline   Reply With Quote
Old March 15th, 2013, 20:01   #15
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
I didn't mean returning a reference though, as that'd cause the same issue
-Ashe- is offline   Reply With Quote
Old March 15th, 2013, 20:10   #16
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
I'm kinda confused now or i just misunderstood your post what issue do you mean??? a simple check can prevent issues don't know what you mean right now . Eitherway i was talking about a function that returns a list of the files found and as a general rule i always use references in function parameters and return types and pointers as mentioned on my previous post. Maybe i expressed myself wrong on my post and you misunderstood it?
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6
@ruantec is offline   Reply With Quote
Old March 15th, 2013, 21:15   #17
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
Code:
vector<T> * f() {
    vector<T> x;
    return &x;
}
Same with a reference
-Ashe- is offline   Reply With Quote
Old March 15th, 2013, 21:47   #18
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,119
Hmmmm seems like we're misunderstanding each other or i just expressed myself wrong... basically what i tried to explain was a very simple way that i believe he may easily comprehend and pretty much this:

Code:
std::vector<std::string> GetFiles(std::string path)
{
	std::vector<std::string> files;
	//logic to fill the vector using the path parameter
	files.push_back("MySuperFile");
	return files;
}

Somewhere in the code:
std::vector<std::string> files = GetFiles("someDir");
std::vector<std::string>::iterator it = files.begin();
while (it != files.end())
{
	//Do something with the object
}
Still unsure of what the problem is but what you posted wasn't what i meant... probably i expressed myself wrong in my post which is nothing new lol
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6
@ruantec is offline   Reply With Quote
Old March 16th, 2013, 02:45   #19
TastEPlasma
Effulgent Plasma Chemist
 
TastEPlasma's Avatar
 
Join Date: Jul 2001
Posts: 518
lol, I have no idea what you two are talking about. ^_^

Regardless, I will continue to use the things mentioned in this thread as topics of study, so my genuine thanks for that.
__________________
Computer Specs:
Spoiler:

*c2d 6320 (1.86) @ 3.3Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *BFG 8800GTX OC x2 *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W Corsair GS *60GB OCZ Vertex x2 in RAID 0 (BOOT/APPs) *400GB WD *ASUS ML248 *Nautilus 500 WC system + Swiftech MCR120 rad on gpu and cpu (single loop)

My GameDev Webpage: TastEPlasma

TastEPlasma is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 23:28.

© 2006 - 2012 Emu Forums | About Emu Forums | Advertisers | Investors | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.