Pages: 1 2 »
  Print  
Author Topic: working_directory, temp_directory and program_directory  (Read 5461 times)
Offline (Unknown gender) TheExDeus
Posted on: October 31, 2012, 09:18:37 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Hello! Some time ago one good man added working_directory+ to every file io function. This is correct way to do this if working_directory is not the same as the exe directory. This is only true when debugging (which is all we can do in ENIGMA because the lack of the fuc*ing COMPILE BUTTON) as you want the source (gmk, gm6, egm etc.) directory for the program to feel like the exe directory (not the /temp in which it actually is in). The problem is that as the only way to get exe is to copy it out of the temp directory. That means the gmk's position is hard coded in  directory and so breaks the shit out of everything. I tried using parameter_string(0), but that isn't implemented (which it should). Here is a topic showing how it could be done:
http://forums.devshed.com/c-programming-42/winmain-and-argv-argc-474770.html
I wasn't able to do that because I didn't try bothering how to convert unicode string to regular char. Then I noticed  temp_directory and program_directory are not set either. The default behavior for POSIX file functions is to have them relative to the file anyway, so deleting the addition of "working_directory+" returns the correct behavior. So basically what these variables should return:
"Debug or Run"
working_directory = directory of gmk (works correctly now) or exe if launched separately from LGM
program_directory = directory of exe no mater where launched from or in what mode. Should be the same as parameter_string(0)
temp_directory = temporary directory. Should be the same as exe directory.
"Clean build (Compile button)"
working_directory = directory of exe
program_directory = directory of exe no mater where launched from or in what mode. Should be the same as parameter_string(0)
temp_directory = temporary directory

So either FINALLY make the "Compile" button work that automatically sets working_directory to exe directory on runtime. Or make the "Debug" and "Run" buttons pass an argument to the exe which would basically tell the exe that it is run from LGM and then set working_directory to the gmk directory.

Anyone willing to do anything?
Logged
Offline (Male) Josh @ Dreamland
Reply #1 Posted on: October 31, 2012, 11:59:09 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
Hi,
  • The working directory is handled by the operating system. It is the exe directory by default. It should not be prepended to filenames under any circumstance, as it is not a variable owned by ENIGMA.
  • "The fucking compile button" works fine, last I checked; you just need to add .exe to the end of the name on Windows. If this has changed, talk to Ism so she can dismiss you formally.
  • Let me once again emphasize that the working directory belongs to the operating system. You should not be storing it or manipulating it in any way.


What I'm going to do is close my eyes and pretend no one prefixed `get_working_directory()` to the given filename. When I open them, sometime after I graduate, I'm hoping it will be gone.
« Last Edit: October 31, 2012, 12:12:00 PM by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) polygone
Reply #2 Posted on: October 31, 2012, 01:08:26 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
Why should it not be prepended to filenames? I don't see any downsides.
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) Josh @ Dreamland
Reply #3 Posted on: October 31, 2012, 02:06:28 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
If the implementation of get_working_directory is correct, the only thing you are doing is risking formatting problems with the underlying operating system.

So, technically, your solution does nothing. Especially on Linux, where \ is a valid character in filenames. The only thing your "fix" does is waste time. First, time to call the function. Then, time to poll the operating system for the path. Then, time to concatenate strings. Then, time to parse the path that it already had parsed as the working directory.

Your solution also confuses HaRRi, who now apparently misunderstands the concept of a working directory.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #4 Posted on: October 31, 2012, 03:07:20 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Josh, the reason working_directory HAS to change when launched from LGM is because the working directory should be the one for the source files (just like in GM it has been since the beginning of time). So you don't have to put your .dll files or your .ini files in the temp directory, but they can safely stay with the source. So you must change working_directory via hard coded path and add that to all IO functions when launched from LGM (just like its done now) or change it on runtime with LGM passing the argument. You can't leave the IO functions without the working_directory prefix unless you are changing the working_directory internally for the POSIX functions. Though I think when you launch a program from another programs directory you do change its working directory... now sure why this doesn't work in this case with LGM.

And the "The fucking compile button" shows this: http://pastebin.com/nnaPG6vV

edit: And I do get the concept of working directory, as I showed what all of the three values should be for the two cases.

Another way which seems the best, could be the easiest, and is basically what I mean with "launch a program from another programs directory" is by making LGM do something like this:
"cd c:/source/dir
c:/tmp/compiled_game.tmp"
One of these things is how GM does it.
« Last Edit: October 31, 2012, 03:17:22 PM by HaRRiKiRi » Logged
Offline (Male) polygone
Reply #5 Posted on: October 31, 2012, 03:15:58 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
The implement works fine on Windows, obviously it needs to be catered to other operating systems but whatever that can be sorted but not being on other operating systems I'm not going to be doing that.
« Last Edit: October 31, 2012, 08:54:17 PM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) Josh @ Dreamland
Reply #6 Posted on: October 31, 2012, 03:23:35 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
You've missed the point.

Your.
Solution.
Does.
Nothing.
Useful.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) polygone
Reply #7 Posted on: October 31, 2012, 08:49:20 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
It does useful on Windows, just need macro it for other platforms.
« Last Edit: October 31, 2012, 08:54:05 PM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) Josh @ Dreamland
Reply #8 Posted on: October 31, 2012, 09:24:36 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
What is it you believe this accomplishes on Windows?


Oh, I see. You people take turns destroying ENIGMA.

The correct implementation of get_working_directory is NOT { return working_directory; }.
The correct implementation of working_directory is #define working_directory get_working_directory() (actually, the correct implementation would move the macro EDL-side, but I digress).
The correct implementation of get_working_directory, on Windows, is as follows:

Code: (C++) [Select]
string get_working_directory() {
  char wd[MAX_PATH];
  size_t len = GetCurrentDirectory(MAX_PATH, wd);
  return string(wd, len);
}

So, with the proper implementation of that function, and not DatZach's ass-backwards hard-coded path value for the working directory, your code is useless.

In other words, while your code presently holds a function, it is wrong that it should do so.

And now I'm twice as pissed off by this whole scenario.
« Last Edit: October 31, 2012, 09:40:05 PM by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #9 Posted on: November 01, 2012, 05:04:37 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
And how the hell you can say it works fine on Windows when I created a freaking post about it NOT working correctly on Windows or probably anywhere. Poly, working_directory is HARD CODED to the source directory, so when I put the exe somewhere else or actually distribute it then the game will crash for other people, because it won't try writing/reading in the current working_directory but in some random path (e.g. "c:/my_folder_structure/someplace/cool_game/source") and that will cause a crash. I had to change the IO functions back for me being able to send the program to another person.

And Josh, I now agree that working_directory shouldn't be touched, and the path problem should be fixed in LGM's side. LGM should be able to launch the game from the source directory and thus fixing all these problems. So the IO functions should be changed back.
Logged
Offline (Male) Josh @ Dreamland
Reply #10 Posted on: November 01, 2012, 02:18:59 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
ENIGMA launches the game. You can change the working directory from which the game is launched by editing the environment ENIGMA creates for it in better_system. You should probably be able to do this without editing better_system.cpp.

I do not recommend defaulting the working directory to the GM6 folder due to the number of novices (and even overconfident experienced users) who end up accidentally scrubbing the contents of the game's working directory while using the file manipulation functions.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #11 Posted on: November 01, 2012, 05:08:18 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
But that is the GM's behavior and for a good reason, mainly, because when you use DLL's or external resources (sprites, sounds etc.) you don't want to put them in temp directory (where they are actually more unsafe) just to be able to run the game from LGM. You want the source file (gmk, gm6, etc.) act like the exe in the file hierarchy. I too had problems that I had to put my FMOD dll inside the temp folder just to launch the game from LGM. In GM I would just put the dll at the same directory as the source.

And if it can be fixed by changing something ENIGMA compiler or LGM then great.
Logged
Offline (Male) Josh @ Dreamland
Reply #12 Posted on: November 01, 2012, 06:14:25 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
What I am suggesting is that you talk to Ism about adding a "workbench" setting to LGM. So your folder will be in ~/Games, and your DLLs will be in ~/ENIGMA/Workbench, or just ~/Workbench, or whatever.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #13 Posted on: November 02, 2012, 05:54:27 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Well the more options, the better. Though I personally prefer the GM way of just putting the source directory as the working directory.

And the "Fucking compile button" doesn't work, which you said it did. Maybe Ism can clarify?
Logged
Offline (Male) polygone
Reply #14 Posted on: November 02, 2012, 10:18:40 AM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
I personally prefer the GM way of just putting the source directory as the working directory.
This.
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Pages: 1 2 »
  Print