// 112 Lines
#include"fileext.h"
//#include"popupdir.h"
l_bool fileext_islink ( l_text file ) {
return ((!strcmp(_strdup(get_extension(file)), "LNK"))||(!strcmp(_strdup(get_extension(file)), "LDV")));
};

l_bool runitnow (l_text file) {
if (fileext_islink(file)) file = io_linkedfile(file);

if (io_isdir(file)) {
/*
t_dirinfo dinfo = io_foreach_file(file, DIF_SIZE, NULL, NULL);

   if (dinfo.files < 1500) {
    t_rect r = VIEW(desktop)->bounds;
    t_point p =  VIEW(desktop)->get_local_point(VIEW(desktop), mouse->where);
    r.a.x += p.x + 5;
    r.a.y += p.y;

    popupdir( file, r, 0, "*.*" );

   } else {
   seal_error(ERR_INFO, "%s \n\n%s", INI_TEXT("This folder is too big to be open in a popup, it contains more than 1500 files."), file);

   }; */
run_file_args("./programs/apps/dc.exe", file);

        return 1;
} else {
return run_file(file);
};
};



l_text get_the_file_text (l_text file, l_text folder) {

l_text folderfile = io_realpath(folder,"desktop.inf");
l_text final = file;
l_text oldtxt = file;
final = getini_fromfile (folderfile, set_format_text(NULL,"%s", strupr(file)),"name" );

if ((final == NULL) && (fileext_islink(file)))  {
final = get_the_file_text2(io_linkedfile(io_realpath(folder,file)));
if ( !strcmp(final, io_filename(io_linkedfile(io_realpath(folder,file)))) ) return oldtxt;
};

if (final == NULL) return oldtxt;

return final;

};

l_text get_the_file_text2 (l_text file) {

return get_the_file_text (io_filename(file),  io_path (file));
};

l_text get_the_file_des (l_text file, l_text folder) {
l_text folderfile = io_realpath(folder,"desktop.inf");
l_text final = getini_fromfile (folderfile, set_format_text(NULL,"%s", strupr(file)),"des" );

if ((final == NULL) && (fileext_islink(file)))  {
final = get_the_file_des2(io_linkedfile(io_realpath(folder,file)));
};

return final ;
};

l_text get_the_file_des2 (l_text file) {
return get_the_file_des ( io_filename(file),  io_path (file));
};

BITMAP *get_the_file_ico (l_text file, l_text folder) {

l_text folderfile = io_realpath(folder,"desktop.inf");
l_text img = getini_fromfile (folderfile, set_format_text(NULL,"%s", strupr(file)),"img" );

if (img == NULL) {
if (fileext_islink(file))  return get_the_file_ico2(io_linkedfile(io_realpath(folder,file)));
if (io_isdir(io_realpath(folder,file))) return load_image("./system/bmp/folder.bmp");
return load_image("./system/bmp/file.bmp");
};

return load_image(img);
};

BITMAP *get_the_file_ico2 (l_text file) {
return get_the_file_ico ( io_filename(file),  io_path (file));
};

BITMAP *get_the_file_ico32 (l_text file, l_text folder) {

l_text folderfile = io_realpath(folder,"desktop.inf");
l_text img = getini_fromfile (folderfile, set_format_text(NULL,"%s", strupr(file)),"img32" );

if (img == NULL) img = getini_fromfile (folderfile, set_format_text(NULL,"%s", strupr(file)),"img" );

if (img == NULL) {
if (fileext_islink(file))  return get_the_file_ico322(io_linkedfile(io_realpath(folder,file)));
if (io_isdir(io_realpath(folder,file))) return load_image("./system/bmp/folder32.bmp");
return load_image("./system/bmp/file32.bmp");
};

return load_image(img);
};

BITMAP *get_the_file_ico322 (l_text file) {
return get_the_file_ico32 ( io_filename(file),  io_path (file));
}

l_bool get_the_file_visible (l_text file, l_text folder) {

l_text folderfile = io_realpath(folder,"desktop.inf");
l_text x = getini_fromfile (folderfile, set_format_text(NULL,"%s", strupr(file)),"hide" );

if (x == NULL) return true;

return false;
};

l_bool get_the_file_visible2 (l_text file) {
return get_the_file_visible ( io_filename(file),  io_path (file));
}

void set_the_file_ext (l_text file, l_text folder,l_text img ,l_text img32, l_text name, l_text des, l_bool visible) {
l_text folderfile = io_realpath(folder,"desktop.inf");
setini_tofile (folderfile, "desktop", "validate",  "1",  INI_STRING);
setini_tofile (folderfile, strupr(file), "des",  des,  INI_STRING);
setini_tofile (folderfile, strupr(file), "img",  img,  INI_STRING);
setini_tofile (folderfile, strupr(file), "img32",  img32,  INI_STRING);
setini_tofile (folderfile, strupr(file), "name", name, INI_STRING);
if (visible == true) {
setini_tofile (folderfile, strupr(file), "hide",  NULL,  INI_STRING);
} else {
setini_tofile (folderfile, strupr(file), "hide",  "1",  INI_STRING);
};
};

void set_the_file_ext2 (l_text file ,l_text img ,l_text img32, l_text name, l_text des, l_bool visible) {
set_the_file_ext( io_filename(file),  io_path (file), img , img32, name, des, visible);
};

