Exemplo n.º 1
0
/*---------------------------------------------------------------------*/
BOOL CreateState(CHAR * filespec, STATE * state)
{
    H_FILE file;

    ArchiveLog(ARC_LOG_VERBOSE, "Creating state file: %s", filespec);

    if ((file = FileOpenForWrite(filespec)) == VOID_H_FILE) {
        _archive_error = ARC_FILE_IO_ERROR;
        ArchiveLog(ARC_LOG_ERRORS, "CreateState: FileOpenForWrite failed");
        return (FALSE);
    }

    if (SerializedWrite(state, _state_template, file) == VOID_UINT32) {
        ArchiveLog(ARC_LOG_ERRORS, "CreateState: SerializedWrite failed");
        return (FALSE);
    }

    if (!FileClose(file)) {
        ArchiveLog(ARC_LOG_ERRORS, "CreateState: FileClose failed");
        _archive_error = ARC_FILE_IO_ERROR;
        return (FALSE);
    }

    return (TRUE);
}
Exemplo n.º 2
0
SQInteger SFFileOpen(HSQUIRRELVM v)
{
    char *filename;
    sq_getstring(Scripts.vm, 2, (const char **)&filename);
    FileOpenForWrite(filename);
    return 0;
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------*/
BOOL OpenStateForWrite(H_ARCHIVE harchive)
{

    _archive[harchive].last_error = ARC_NO_ERROR;
    _archive_error = ARC_NO_ERROR;

    /* Create filespec for state file and open for read */
    sprintf(_archive[harchive].filespec, "%s%c%s", _archive[harchive].path,
        PATH_DELIMITER, STATE_FILENAME);
    if ((_archive[harchive].file = FileOpenForRead(_archive[harchive].filespec)) == VOID_H_FILE) {
        ArchiveLog(ARC_LOG_ERRORS, "OpenStateForWrite: Error opening state file: %s", _archive[harchive].filespec);
        _archive[harchive].last_error = ARC_FILE_IO_ERROR;
        return (FALSE);
    }
    /* Read the current state */
    if (!ReadState(harchive))
        return (FALSE);
    if (_archive[harchive].state.write) {
        ArchiveLog(ARC_LOG_ERRORS, "OpenStateForWrite: Archive is open for write by another process: %s", _archive[harchive].path);
        _archive[harchive].last_error = ARC_PERMISSION_DENIED;
        return (FALSE);
    }
    if (!FileClose(_archive[harchive].file)) {
        _archive[harchive].last_error = ARC_FILE_IO_ERROR;
        return (FALSE);
    }

    /* Reopen for write */
    if ((_archive[harchive].file = FileOpenForWrite(_archive[harchive].filespec)) == VOID_H_FILE) {
        ArchiveLog(ARC_LOG_ERRORS, "OpenStateForWrite: Error opening state file: %s", _archive[harchive].filespec);
        _archive[harchive].last_error = ARC_FILE_IO_ERROR;
        return (FALSE);
    }
    /* Mark as open for write */
    _archive[harchive].state.write = TRUE;
    /* Archive is open for read-write access */
    _archive[harchive].access = ARC_WRITE;
    /* Start the update timer */
    Timer48Start(&_archive[harchive].update, 0);
    if (!WriteState(harchive))
        return (FALSE);

    /* Start the update timer */
    Timer48Start(&_archive[harchive].update, UPDATE_INTERVAL);

    ArchiveLog(ARC_LOG_MAXIMUM, "State file opened for write: %s", _archive[harchive].filespec);

    return (TRUE);
}
Exemplo n.º 4
0
int SFFileOpen(lua_State* l)
{
    char *filename = (char *)lua_tostring(Scripts.vm, 1);
    FileOpenForWrite(filename);
    return 0;
}