file_open_write and dialog

Posted By: RyuMaster

file_open_write and dialog - 12/07/08 14:26

Hi! I'm getting very odd behavior. I think it might be a bug.
I'm using this script for calling FileOpenDialog, Lite-C;

Quote:
OPENFILENAME ofd;
STRING FileName = str_create(#255);
FileName.chars=0; VERY IMPORTANT
FillMemory(&ofd,sizeof(ofd),0);
ofd.Flags=OFN_PATHMUSTEXISTOFN_FILEMUSTEXIST;
ofd.lStructSize=sizeof(ofd);
ofd.hwndOwner=hWnd;
ofd.lpstrFilter =All Files0.00;
ofd.lpstrInitialDir = _chr(work_dir);
ofd.lpstrFile=FileName.chars;
ofd.nMaxFile=255;
ofd.lpstrTitle=Open;
if (GetOpenFileName(&ofd))
{
process_entry(ofd.lpstrFile);
}


Now, I have this load-level script.

Quote:
if (key_f6) // Quick Save Level map data
{
var filehandle;
int j = 0;
STRING* temp = "#255";
str_cpy(save_dir,"");

filehandle = file_open_write("objects\\lab.txt"); // opens the file address.txt to read



and bla bla bla


If I load file, WITHOUT USING FILE DIALOG TO OPEN SOME FILE PRIOR TO IT, file "lab.txt" is loaded from root directory.
If I load file, BY LOADING SOME FILE WITH FILE DIALOG FROM FOLDER "objects", file "lab.txt" is loaded from "objects" directory.

Now, changing save_dir does absolutely nothing. I may delete it, or change to some value. It looks like absolutely irrelevant?
Also, I have this at script start:


Quote:
#define PRAGMA_PATH "D:\quntummist\lab\game";
#define PRAGMA_PATH "D:\quntummist\objects\props";
#define PRAGMA_PATH "D:\quntummist\objects\walls";
#define PRAGMA_PATH "objects";
#define PRAGMA_PATH "D:\quntummist\objects";


Posted By: Tobias

Re: file_open_write and dialog - 12/07/08 15:38

Maybe, you changed the directory in the dialog?
Posted By: RyuMaster

Re: file_open_write and dialog - 12/09/08 19:21

No, I'm tracing save_dir and work_dir in debug window. They do not change. But file_write supposed to write into save_dir folder.
Posted By: jcl

Re: file_open_write and dialog - 12/10/08 11:15

Originally Posted By: manual
If a path is given with the file name, the file is opened from that path instead of the save_dir or work folder.

Your poor computer just tries to please you by doing what you told it. When you give a subfolder, it tries to open the file from that subfolder of the current directory. Window's file open dialogs change the current directory. If that's bad for your project, you must change it back.

That's why we suggest not to use paths in file names. When you leave the protected room of engine functions and wander into the open field of the Windows API, don't complain about the cold wind of real programming blowing into your face.
Posted By: RyuMaster

Re: file_open_write and dialog - 12/10/08 12:53

Thanks for answering!

You say I can change current dir back? That was first ideas I came into.

But, work_dir and save_dir stays the same, while "lab.txt" is accessed from "objects" folder, as I wrote.

So, current_dir is some variable which is stored outside of 3DGS engine and can be traced only from within windows API?
But if 3DGS uses it, maybe it stores current_dir somewhere also, so I could change it?



Regards,
Konstantin.
Posted By: Petra

Re: file_open_write and dialog - 12/10/08 13:02

Hi Ryumaster, work_dir is not a folder. It is a string pointer.

Originally Posted By: manual
work_dir

Type:
string*, read-only

For changing a string you need functions like str_cpy, but in case of work_dir you probably can't change it at all because its marked as read-only and thus not changed at runtime.

In Windows, you change the current folder with a function like "_chdir". As I understand the manual the string work_dir contains the name of your original game folder and will almost certainly have no effect on your current directory!

Hope this helps!

Posted By: RyuMaster

Re: file_open_write and dialog - 12/10/08 13:13

In Windows, you change the current folder with a function like "_chdir"

Thanks a lot. I think I'll try changing current_dir from WINAPI, I hope this would not bring any more errors.
© 2024 lite-C Forums