⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 files.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 2 页
字号:

            if ( ind ) (*ind)++;

        };


        return true;

    };

    return false;

};

////////////////////////////////////////////////////////////////////////////////
l_text  io_parentdir ( l_text path )
{
/*
   l_text endpath = NULL;
   l_text path2 = _strdup(path);

   if ( path2 ) {

      l_text last_slash = strrchr(path2, '/');

      if ( last_slash && !(*(last_slash+1)) ) {

          (*last_slash) = '\0';

          last_slash = strrchr(path2, '/');

      };

      endpath = stridup(path2, strsize(path2, last_slash));

   };

   _free(path2);

   return endpath;
  */
  l_text tmp = io_realpath ( path , "../" );
  l_text parent = ResolveFileName ( tmp );
  _free(tmp);
  return parent;

};
////////////////////////////////////////////////////////////////////////////////
l_text  io_uniquedir ( l_text path )
{
   l_char dir[9] = "DIR0";
   l_int  i = 0;
   l_text rp = io_realpath(path, dir);
   l_text ret = NULL;

   while ( i < 99999 && io_isdir(rp) ) { /* if directory exist */

       itoa(i, &dir[3], 10);

       i++;

       _free(rp);

       rp = io_realpath(path, dir);

   };

   if (i < 99999) ret = _strdup(dir);

   _free(rp);

   return ret;
};
////////////////////////////////////////////////////////////////////////////////
l_bool io_isfilename ( l_text file ) {
   if ( file ) {
       if ( !stricmp(file, "..") ) return false;
       if ( !stricmp(file, ".") ) return false;
       return true;
   };
   return false;
};
////////////////////////////////////////////////////////////////////////////////
l_bool io_isext ( l_text file ) {
   if ( file ) {
       if ( strchr(file, '*') || strchr(file, '?') )
           return true;
   };
   return false;
};
////////////////////////////////////////////////////////////////////////////////
l_bool  io_issame ( l_text file1, l_text file2 )
{
  l_bool ret = false;

  l_text f1;
  l_text f2;

  l_int  x1;
  l_int  x2;

  if ( !file1 || !file2 ) return false;

  f1 = _strdup(file1);
  f2 = _strdup(file2);

  x1 = strlen(f1)-1;
  x2 = strlen(f2)-1;

  if ( *(f1+x1) == '\\' || *(f1+x1) == '/' ) *(f1+x1) = '\0';
  if ( *(f2+x2) == '\\' || *(f2+x2) == '/' ) *(f2+x2) = '\0';

  if ( f1 && f2 && !stricmp(f1, f2) )

       ret = true;

  _free(f1);
  _free(f2);

  return ret;

};
////////////////////////////////////////////////////////////////////////////////
p_list filesop = NULL;

p_fileop fo_directory = NULL;
p_fileop fo_deffile   = NULL;
////////////////////////////////////////////////////////////////////////////////
p_fileop GetFileopForExp ( l_text ext ) {

  if ( !ext ) return NULL;

  if ( filesop && filesop->last ) {

    p_item x = filesop->first(filesop);
    p_item f = x;

    if  ( f )
    do {

       if ( !stricmp( FILEOP(x->rec)->ext , ext ) ) return FILEOP(x->rec);

       x = x->next;

    } while ( x != f );

  };

  return fo_deffile;
};
////////////////////////////////////////////////////////////////////////////////
p_fileop GetFileopForFile ( l_text file ) {
  if ( !file ) return NULL;

  if ( io_isfile(file) ) {
    return GetFileopForExp ( get_extension ( file ) );
  } else if ( io_isdir(file) ) {
    return fo_directory;
  } else {
    return NULL;
  };
};
////////////////////////////////////////////////////////////////////////////////
p_fileop GetFileopForFileAttrib ( l_text file, l_int attrib ) {
  if ( !file ) return NULL;

  if ( !( attrib & FA_DIREC ) ) {
    l_text   ext = get_extension ( file );
    p_fileop   o = GetFileopForExp ( ext );
    return o;
  } else {
    return fo_directory;
  };
};
////////////////////////////////////////////////////////////////////////////////
p_fileop fo_init ( p_fileop o,
                       l_text ext,
                       BITMAP *ico32,
                       BITMAP *ico16,
                       BITMAP *(*GetIcon)( l_text filename, l_int size, l_int *ownmem ),
                       l_text  description ) {

if ( !o ) return NULL;
o->ext = ext;
o->ico16 = ico16;
o->ico32 = ico32;
o->GetIcon = GetIcon;
o->description = description;
o->def = NULL;
o->actions = list_init(malloc(sizeof(t_list)), NULL, NULL);
return o;
};
////////////////////////////////////////////////////////////////////////////////
void fo_add_act ( p_fileop i,
                  p_fileact o,
                  l_text   cmd,
                  l_int   (*act) ( l_text filename, l_text args),
                  l_text   txt,
                  l_bool   def ) {

if ( !o || !i ) return;

o->cmd = cmd;
o->act = act;
o->txt = txt;
i->actions->insert(i->actions,o);
if ( def ) i->def = o;

};
////////////////////////////////////////////////////////////////////////////////
BITMAP*  get_icon_for_file_ex ( l_text filename, l_int attrib, l_int *ownmem, l_int size ) {
  p_fileop o = NULL; // faster because we know attrib of file
  BITMAP  *b = NULL;

  if ( !filename ) return NULL;

  o = GetFileopForFileAttrib(filename, attrib);

  if ( !o ) return NULL;

  if ( o->GetIcon ) {
    b = o->GetIcon ( filename, size, ownmem );
    if ( b ) return b;
  };

  if ( ownmem ) (*ownmem) = 0;

  if ( size < 32 )
    b = o->ico16;
  else
    b = o->ico32;

  return b;
};
////////////////////////////////////////////////////////////////////////////////
BITMAP*  get_icon_for_file ( l_text filename, l_int attrib, l_int *ownmem ) {
  return  get_icon_for_file_ex( filename, attrib, ownmem, 16 );
};
////////////////////////////////////////////////////////////////////////////////
BITMAP*  load_file_icon ( l_char *args, l_int size, l_int *ownmem ) {
  return  get_icon_for_file_ex( args, io_isdir(args)?FA_DIREC:0, ownmem, size );
};
////////////////////////////////////////////////////////////////////////////////
l_int    run_file_args ( l_text file, l_text args ) {
  p_fileop o;
  if ( !file ) return 0;

  o = GetFileopForFile(file);
  if ( !o ) return 0;

  if ( o->def ) {
    if ( o->def->act ) return o->def->act ( file, args );
    if ( o->def->cmd ) return DLXLoad(o->def->cmd , file ) ? 1 : 0 ;
  };
  return 0;
};
////////////////////////////////////////////////////////////////////////////////
l_int    run_file ( l_text file ) {
  return run_file_args ( file, NULL );
};
////////////////////////////////////////////////////////////////////////////////
l_int XDLLoad ( l_text file, l_text args ) {
   return DLXLoad(file,args);
};
////////////////////////////////////////////////////////////////////////////////
BITMAP *icon_icofile ( l_text filename, l_int size, l_bool *ownmem ) {
  if ( ownmem ) *(ownmem) = true;
  if ( filename ) {
    return load_ico(filename,size,( get_depth(screen) < 16 ) ? 16 : 256);
  };
  return NULL;
};
////////////////////////////////////////////////////////////////////////////////
void ini_ext_runner ( void ) {

  p_registry_search inf = (p_registry_search) malloc(sizeof(t_registry_search));

  p_fileop tmp = NULL;

  filesop = list_init(malloc(sizeof(t_list)), NULL, NULL);


  fo_directory = fo_init( malloc(sizeof(t_fileop)), NULL, IMG_DIR32, IMG_DIR16, NULL, TXT_DIRECTORY );

  fo_deffile = fo_init ( malloc(sizeof(t_fileop)), NULL, IMG_FILE32, IMG_FILE16, NULL, "Unknow file type" );

  tmp = fo_init ( malloc(sizeof(t_fileop)), "s2a", IMG_APP32, IMG_APP16, NULL, "Application file (executable)" );
  fo_add_act(tmp,malloc(sizeof(t_fileact)),NULL,&XDLLoad,"Run",true);
  filesop->insert(filesop,tmp);

  tmp = fo_init ( malloc(sizeof(t_fileop)), "xdl", IMG_APP32, IMG_APP16, NULL, "Dynamic file (executable)" );
  fo_add_act(tmp,malloc(sizeof(t_fileact)),NULL,&XDLLoad,"Load",true);
  filesop->insert(filesop,tmp);

 tmp = fo_init ( malloc(sizeof(t_fileop)), "sss", IMG_APP32, IMG_APP16, NULL, "Seal screen saver file (executable)" );
  fo_add_act(tmp,malloc(sizeof(t_fileact)),NULL,&XDLLoad,"Test",true);
  filesop->insert(filesop,tmp);


  tmp = fo_init ( malloc(sizeof(t_fileop)), "ln", IMG_FILE32, IMG_FILE16, &lnk_get_link_icon, "Link" );
  fo_add_act(tmp,malloc(sizeof(t_fileact)),NULL,&lnk_run_link,"Open",true);
  filesop->insert(filesop,tmp);

  tmp = fo_init ( malloc(sizeof(t_fileop)), "ico", IMG_FILE32, IMG_FILE16, &icon_icofile, "Icon file" );
  filesop->insert(filesop,tmp);

    if ( reg_find_first("system/filetypes", inf) ) do {
      l_text  key        = inf->name;
      l_text  key_loader = key_in_path(key,"loader");
      l_text  key_ico16  = key_in_path(key,"icon16");
      l_text  key_ico32  = key_in_path(key,"icon32");
      l_text  exp        = _strdup(inf->key->name);
      l_text  desc       = get_key(inf->name);
      l_text  loader     = NULL;
      l_text  ico16      = NULL;
      l_text  ico32      = NULL;
      BITMAP *icon16;
      BITMAP *icon32;

      if ( key_exists (key_loader) ) loader = get_key(key_loader);
      if ( key_exists (key_ico16) )  ico16 = get_key(key_ico16);
      if ( key_exists (key_ico32) )  ico32 = get_key(key_ico32);



      if ( stricmp(exp,"folder") )
        tmp = GetFileopForExp(exp);
      else
        tmp = fo_directory;

      if ( tmp == fo_deffile ) {

        if ( ico16 )
          icon16 = load_image(ico16);
        else
          icon16 = IMG_FILE16;
        if ( ico32 )
          icon32 = load_image(ico32);
        else
          icon32 = IMG_FILE32;

        tmp = fo_init ( malloc(sizeof(t_fileop)), exp, icon32, icon16, NULL, desc );
        filesop->insert(filesop,tmp);
      };

      if ( loader ) fo_add_act(tmp,malloc(sizeof(t_fileact)),loader,NULL,"Open",true);

      _free(key_ico16);
      _free(key_ico32);
      _free(key_loader);
      _free(ico16);
      _free(ico32);

    } while (reg_find_next(inf));

  _free(inf);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -