Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Opening a file from same folder as your App
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
angerist
Grandmaster Cheater Supreme
Reputation: 0

Joined: 18 Jun 2007
Posts: 1011
Location: Australia.

PostPosted: Sun Oct 05, 2008 12:57 am    Post subject: Opening a file from same folder as your App Reply with quote

Alright so I have no control over where the users choose to save my App so I cant use directory's. I know how to do this in C# but I really need to know how to do it in either Delphi or VB. Preferably Delphi.


Here's the code I created in C#

Code:
string _sAppPathName = Process.GetCurrentProcess().MainModule.FileName;

string _sDataFilePath = _sAppPath.Substring(0, _sAppPath.Length - (_sAppPath.Length - _sAppPath.LastIndexOf(@"\"))) + @"\yourfilename.yourextension";


And on a different note I also need to find out how to replace files. So say if I had the files that I wanted to replace in the same folder as my app and I wanted them to go to a directory on the users computer with a press of a button. Any suggest and snippets would be appreciated


I need this in delphi. Looking forward to some answers

Thankyou,

Angerist.

_________________


Last edited by angerist on Mon Oct 06, 2008 2:05 am; edited 1 time in total
Back to top
View user's profile Send private message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Sun Oct 05, 2008 1:03 am    Post subject: Reply with quote

To get the application path in Delphi do

Code:
strFilePath := ExtractFilePath(Application.ExeName); //strFilePath is a string


No idea about the rest.
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Sun Oct 05, 2008 1:11 am    Post subject: Reply with quote

there is no rest, just add whatever the file name is to the end of that string and run

im failry sure there is an easier way in C# too, that looks odd

_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Oct 05, 2008 1:51 am    Post subject: Reply with quote

Not sure if this is what you want.

GetModuleFileName returns the path + filename for the calling executable. Simply make the string shorter by a length of what how long the filename is. This returns path.

Then use CreateFile (check return of it) or the function from shlwapi.dll (forgot its name right now) to check whether the file to open is present.
Back to top
View user's profile Send private message
angerist
Grandmaster Cheater Supreme
Reputation: 0

Joined: 18 Jun 2007
Posts: 1011
Location: Australia.

PostPosted: Sun Oct 05, 2008 1:58 am    Post subject: Reply with quote

Well I'll TRY all of your suggestions and reply. Thankyou
_________________


Last edited by angerist on Sun Oct 05, 2008 10:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Sun Oct 05, 2008 2:49 am    Post subject: Reply with quote

i think you missed a word there buddy Razz
_________________
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sun Oct 05, 2008 4:12 am    Post subject: Reply with quote

There's also GetCurrentDirectory
http://msdn.microsoft.com/en-us/library/aa364934
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Oct 05, 2008 4:26 am    Post subject: Reply with quote

See this thread for why it is preferable to use GetModuleFileName than GetCurrentDirectory :

http://forum.cheatengine.org/viewtopic.php?t=276594&start=0&postdays=0&postorder=asc&highlight=

Of course, both do work.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sun Oct 05, 2008 4:36 am    Post subject: Reply with quote

Slugsnack wrote:
See this thread for why it is preferable to use GetModuleFileName than GetCurrentDirectory :

http://forum.cheatengine.org/viewtopic.php?t=276594&start=0&postdays=0&postorder=asc&highlight=

Of course, both do work.


I could argue that GetCurrentDirectory is preferable because it takes less parameters. If a programmer forgets that he changed the directory, it's their own fault.
Back to top
View user's profile Send private message MSN Messenger
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Sun Oct 05, 2008 11:10 am    Post subject: Reply with quote

Usually when you supply only the file w/ extension, the API should look for it in the same folder.
_________________
Back to top
View user's profile Send private message
ups2000ups
I post too much
Reputation: 0

Joined: 31 Jul 2006
Posts: 2471

PostPosted: Sun Oct 05, 2008 11:38 am    Post subject: Reply with quote

path := ExtractFilePath(ParamStr(0))+'filename.exe';
_________________
dont complain about my english...
1*1 = 2?
Back to top
View user's profile Send private message
angerist
Grandmaster Cheater Supreme
Reputation: 0

Joined: 18 Jun 2007
Posts: 1011
Location: Australia.

PostPosted: Sun Oct 05, 2008 10:39 pm    Post subject: Reply with quote

I cant really use GetCurrentDirectory its really unstable. I have no control over where people put my app.
_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Mon Oct 06, 2008 12:12 am    Post subject: Reply with quote

angerist wrote:
I cant really use GetCurrentDirectory its really unstable. I have no control over where people put my app.
/facepalm. I advise you learn what GetCurrentDirectory does.
_________________
Back to top
View user's profile Send private message
Wintermoot
Expert Cheater
Reputation: 0

Joined: 08 Nov 2007
Posts: 198

PostPosted: Mon Oct 06, 2008 12:40 am    Post subject: Reply with quote

From what I remember of VB, App.Path works...

@angerist:
C#
Code:

Application.StartupPath;

VB.NET
Code:

Application.StartupPath


I have checked that both of those work after using an open file dialog.
Back to top
View user's profile Send private message
angerist
Grandmaster Cheater Supreme
Reputation: 0

Joined: 18 Jun 2007
Posts: 1011
Location: Australia.

PostPosted: Mon Oct 06, 2008 2:01 am    Post subject: Reply with quote

sponge wrote:
angerist wrote:
I cant really use GetCurrentDirectory its really unstable. I have no control over where people put my app.
/facepalm. I advise you learn what GetCurrentDirectory does.


Sorry man no need to get stressed out I'm new to programming. I thought GetCurrentDirectory is the last directory that you've been to. But yeh i'll do some research.

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites