Ejemplo n.º 1
0
TbBool load_column_file(LevelNumber lv_num)
{
    unsigned long i;
    long k;
    unsigned short n;
    long total;
    unsigned char *buf;
    long fsize;
    if ((game.operation_flags & GOF_ColumnConvert) != 0)
    {
        convert_old_column_file(lv_num);
        game.operation_flags &= ~GOF_ColumnConvert;
    }
    fsize = 8;
    buf = load_single_map_file_to_buffer(lv_num,"clm",&fsize,LMFF_None);
    if (buf == NULL)
      return false;
    clear_columns();
    i = 0;
    total = llong(&buf[i]);
    i += 4;
    // Validate total amount of columns
    if ((total < 0) || (total > (fsize-8)/sizeof(struct Column)))
    {
      total = (fsize-8)/sizeof(struct Column);
      WARNMSG("Bad amount of columns in CLM file; corrected to %ld.",total);
    }
    if (total > COLUMNS_COUNT)
    {
      WARNMSG("Only %d columns supported, CLM file has %ld.",COLUMNS_COUNT,total);
      total = COLUMNS_COUNT;
    }
    // Read and validate second amount
    game.field_14AB3F = llong(&buf[i]);
    if (game.field_14AB3F >= COLUMNS_COUNT)
    {
      game.field_14AB3F = COLUMNS_COUNT-1;
    }
    i += 4;
    // Fill the columns
    for (k=0; k < total; k++)
    {
        struct Column *colmn;
        colmn = &game.columns_data[k];
        LbMemoryCopy(colmn, &buf[i], sizeof(struct Column));
        //Update top cube in the column
        n = find_column_height(colmn);
        set_column_floor_filled_subtiles(colmn, n);
        i += sizeof(struct Column);
    }
    LbMemoryFree(buf);
    return true;
}
Ejemplo n.º 2
0
// 'Fl_FileBrowser::load()' - Load a directory into the browser.
int                                         // O - Number of files loaded
    Fl_File_Browser::load(const Fl_String &dir) // I - Directory to load
{   
    Fl_String old_dir(directory());
    m_dir_ds.directory(dir);

    clear();
    clear_columns();
    sort_col(1);
    m_up_item = 0;

    if(dir.empty()) {
        header()->add_column("", 20);

        // No directory specified:
        //  - For UNIX list all mount points.
        //  - For Win32 list all valid drive letters.

        //icon      = Fl_FileIcon::find("any", Fl_FileIcon::DEVICE);
        //if (icon == (Fl_FileIcon *)0)
        //  icon = Fl_FileIcon::find("any", Fl_FileIcon::DIR);

        begin();
        char filename[FL_PATH_MAX];
#ifdef _WIN32
        header()->add_column(_("File"), 100);
        header()->add_column(_("Type"), 100);
        header()->add_column(_("Capacity"), 100);
        header()->add_column(_("Free Space"), 100);

        // Drive available bits
        DWORD drives = GetLogicalDrives();
        for(int i = 'A'; i <= 'Z'; i ++, drives >>= 1) {
            if (drives & 1) {
                Fl_ListView_Item *item = new Fl_ListView_Item();
                item->image(&hd_pix);
                snprintf(filename, sizeof(filename)-1, "%c:\\", i);
                item->label(1, filename);

                Fl_File_Attr *attr = fl_file_attr(filename);
                if(attr->flags & Fl_File_Attr::DEVICE)
                {
                    uint type = GetDriveTypeA(filename);
                    const char *typestr=_(types[0]);

                    if (type==DRIVE_CDROM)      { typestr=_(types[4]); item->image(&cd_pix); }
                    else if (type==DRIVE_REMOVABLE) { typestr=_(types[5]); item->image(&floppy_pix); }
                    else if (type==DRIVE_FIXED)     typestr=_(types[6]);
                    else if (type==DRIVE_REMOTE)        typestr=_(types[7]);
                    else if (type==DRIVE_RAMDISK)   typestr=_(types[8]);

                    item->label(2, typestr);

                    uint s = 0;
                    Fl_String suffix;
                    if((s = get_dev_size(attr->capacity, suffix))>0) {
                        item->label(3, Fl_String(s)+" "+suffix);
                    }
                    if((s = get_dev_size(attr->free, suffix))>0) {
                        item->label(4, Fl_String(s)+" "+suffix);
                    }

                    /*
                     //TOO SLOW!!!
                     char drivename[255];
                     if(GetVolumeInformation(
                     filename, drivename, sizeof(drivename)-1,
                     NULL, NULL, NULL, NULL, 0))
                     {
                     if(drivename[0])
                     snprintf(fname, sizeof(fname)-1, "%s (%s)", filename, drivename);
                     }
                     */
                }

            }
        }
#else
        header()->add_column(_("File"), 100);
        header()->add_column(_("Device"), 100);
        header()->add_column(_("Type"), 100);

        FILE    *mtab = 0;      // /etc/mtab or /etc/mnttab file
        char    line[1024];     // Input line
        char    dev[256];       // Device name
        char    fstype[256];    // Filesystem type

        // Open the file that contains a list of mounted filesystems...
#  if defined(__hpux) || defined(__sun)
        // Fairly standard
        mtab = fl_fopen("/etc/mnttab", "r");
#  elif defined(__sgi) || defined(linux)
        // More standard
        mtab = fl_fopen("/etc/mtab", "r");
#  endif
        // Otherwise fallback to full list
        if(mtab == NULL) mtab = fl_fopen("/etc/fstab", "r");
        if(mtab == NULL) mtab = fl_fopen("/etc/vfstab", "r");

        if (mtab != NULL)
        {
            while (fgets(line, sizeof(line), mtab) != NULL)
            {
                if (line[0] == '#' || line[0] == '\n')
                    continue;
                if (sscanf(line, "%255s%4095s%255s", dev, filename, fstype) != 3)
                    continue;
                if(!strcasecmp(dev, "none"))
                    continue;

                Fl_ListView_Item *item = new Fl_ListView_Item();
                item->image(&hd_pix);
                item->label(1, filename);
                item->label(2, dev);
                item->label(3, fstype);
            }
            fclose(mtab);
        }
#endif // _WIN32
        end();
        resizable_col(0, false);
        return children();

    } else {