示例#1
0
void FiosGetDrives(FileList &file_list)
{
	TCHAR drives[256];
	const TCHAR *s;

	GetLogicalDriveStrings(lengthof(drives), drives);
	for (s = drives; *s != '\0';) {
		FiosItem *fios = file_list.Append();
		fios->type = FIOS_TYPE_DRIVE;
		fios->mtime = 0;
		seprintf(fios->name, lastof(fios->name),  "%c:", s[0] & 0xFF);
		strecpy(fios->title, fios->name, lastof(fios->title));
		while (*s++ != '\0') { /* Nothing */ }
	}
}
示例#2
0
bool
Msg2Msg::AddNewSndFile(const char* fileName)
{
    ListableFile *newFilePtr = new ListableFile();
    if(!newFilePtr)
    {
        DMSG(0,"Msg2MsgAddNewSndSocket error allocing new socket\n");
        return false;
    }
    if(!(newFilePtr->Open(fileName,O_WRONLY | O_CREAT)))
    {
        DMSG(0,"Msg2MsgAddNewSndFile error opening the file \"%s\"\n",fileName);
        delete newFilePtr;
        return false;
    }
    sndFiles.Append(*newFilePtr);
    return true;
}
示例#3
0
文件: os2.cpp 项目: J0anJosep/OpenTTD
void FiosGetDrives(FileList &file_list)
{
    uint disk, disk2, save, total;

#ifndef __INNOTEK_LIBC__
    _dos_getdrive(&save); // save original drive
#else
    save = _getdrive(); // save original drive
    char wd[MAX_PATH];
    getcwd(wd, MAX_PATH);
    total = 'z';
#endif

    /* get an available drive letter */
#ifndef __INNOTEK_LIBC__
    for (disk = 1;; disk++) {
        _dos_setdrive(disk, &total);
#else
    for (disk = 'A';; disk++) {
        _chdrive(disk);
#endif
        if (disk >= total)  break;

#ifndef __INNOTEK_LIBC__
        _dos_getdrive(&disk2);
#else
        disk2 = _getdrive();
#endif

        if (disk == disk2) {
            FiosItem *fios = file_list.Append();
            fios->type = FIOS_TYPE_DRIVE;
            fios->mtime = 0;
#ifndef __INNOTEK_LIBC__
            snprintf(fios->name, lengthof(fios->name),  "%c:", 'A' + disk - 1);
#else
            snprintf(fios->name, lengthof(fios->name),  "%c:", disk);
#endif
            strecpy(fios->title, fios->name, lastof(fios->title));
        }
    }

    /* Restore the original drive */
#ifndef __INNOTEK_LIBC__
    _dos_setdrive(save, &total);
#else
    chdir(wd);
#endif
}

bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
{
#ifndef __INNOTEK_LIBC__
    struct diskfree_t free;
    char drive = path[0] - 'A' + 1;

    if (tot != NULL && _getdiskfree(drive, &free) == 0) {
        *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector;
        return true;
    }

    return false;
#else
    uint64 free = 0;

#ifdef HAS_STATVFS
    {
        struct statvfs s;

        if (statvfs(path, &s) != 0) return false;
        free = (uint64)s.f_frsize * s.f_bavail;
    }
#endif
    if (tot != NULL) *tot = free;
    return true;
#endif
}

bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
{
    char filename[MAX_PATH];

    snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
    return stat(filename, sb) == 0;
}