Exemplo n.º 1
0
bool Db_File::Open (int part_index)
{
    if (Is_Open ()) {
        Close ();
    } else if (File_Format () == DEFAULT_FORMAT) {
        File_Format (DEFAULT_FORMAT);
    }
    bool messages = exe->Send_Messages ();
    if (part_index > 0) exe->Send_Messages (false);

    bool stat = Filename (part_index);

    if (stat) {
        int hold = part_num;

        if (part_flag) {
            part_num = exe->Partition_Number (part_index);
        } else {
            part_num = -1;
        }
        stat = Open ();
        if (stat) {
            if (part_index >= num_files) num_files = part_index + 1;
            if (!part_flag) part_num = part_index;
        } else {
            part_num = hold;
        }
    }
    exe->Send_Messages (messages);
    return (stat);
}
Exemplo n.º 2
0
bool Db_File::Close (void)
{
    bool stat = true;

    if (Is_Open ()) {
        first_open = false;

        if (File_Format () == SQLITE3) {
            if (read_stmt != 0) {
                sqlite3_finalize (read_stmt);
                read_stmt = 0;
            }
            if (read_nest != 0) {
                sqlite3_finalize (read_nest);
                read_nest = 0;
            }
            if (insert_stmt != 0) {
                sqlite3_finalize (insert_stmt);
                insert_stmt = 0;
            }
            if (insert_nest != 0) {
                sqlite3_finalize (insert_nest);
                insert_nest = 0;
            }
            if (db_file != 0) {
                sqlite3_exec (db_file, "COMMIT", 0, 0, 0);
                sqlite3_close (db_file);
                db_file = 0;
            }
        } else {
            file.close ();
        }
    }
    return (stat);
}
Exemplo n.º 3
0
FileError File::seek( FileHandle fh, FileSeek seek, int offset )
{
	DWORD moveMethod = 0;
	switch( seek )
	{
		case FILE_SEEK_BEGIN:
			moveMethod = FILE_BEGIN;
			break;

		case FILE_SEEK_CURRENT:
			moveMethod = FILE_CURRENT;
			break;

		case FILE_SEEK_END:
			moveMethod = FILE_END;
			break;

		default:
			// Should never happen
			// Did you add an additional seek method without updating this switch statement?
			GameAssert( 0 );
	}

	if( !Is_Open( fh ) || !Seek_Position( fh, offset, moveMethod ) )
		return FILE_SEEK_FAIL;
	else
		return FILE_SUCCESS;
}
Exemplo n.º 4
0
FileError File::read( FileHandle fh, void* buffer, size_t inSize )
{
	if( !Is_Open( fh ) || !Read_Bytes( fh, buffer, inSize ) )
		return FILE_READ_FAIL;
	else
		return FILE_SUCCESS;
}
Exemplo n.º 5
0
FileError File::write( FileHandle fh, const void* buffer, size_t inSize )
{
	if( !Is_Open( fh ) || !Write_Bytes( fh, buffer, inSize ) )
		return FILE_WRITE_FAIL;
	else
		return FILE_SUCCESS;
}
Exemplo n.º 6
0
FileError File::close( FileHandle fh )
{
	if( !Is_Open( fh ) || !Close_File( fh ) )
		return FILE_CLOSE_FAIL;
	else
		return FILE_SUCCESS;
}
Exemplo n.º 7
0
FileError File::flush( FileHandle fh )
{
	if( !Is_Open( fh ) || !Flush_File( fh ) )
		return FILE_FLUSH_FAIL;
	else
		return FILE_SUCCESS;
}
Exemplo n.º 8
0
// why is it even an int to begin with? you can't have NEGATIVE file offsets...
FileError File::tell( FileHandle fh, unsigned long& offset )
{
	DWORD position;

	if( !Is_Open( fh ) || !Tell_Position( fh, position ) )
	{
		return FILE_TELL_FAIL;
	}
	else
	{
		offset = position;
		return FILE_SUCCESS;
	}
}
Exemplo n.º 9
0
bool Db_File::Open (string path)
{
    if (!path.empty ()) {
        Filename (path);
    } else if (filename.empty ()) {
        return (false);
    }
    if (Is_Open ()) {
        Close ();
    } else if (File_Format () == DEFAULT_FORMAT) {
        File_Format (DEFAULT_FORMAT);
    }
    bool create_flag, exist_flag;

    if (File_Access () == CREATE) {
        create_flag = true;
        exist_flag = f_exist (filename);
        num_records = record_num = max_record_num = 0;
    } else {
        create_flag = exist_flag = false;
    }
    if (!Db_Open (filename)) {
        if (exe->Send_Messages ()) {
            string message (((create_flag) ? "Creating " : "Opening "));
            message += File_Type ();
            exe->File_Error (message, filename);
        }
        return (Status (NOT_OPEN));
    } else {
        if (create_flag && !File_Type ().Starts_With ("New") && !File_Type ().Starts_With ("Output")) {
            File_Type (String ("New %s") % File_Type ());

            if (File_Format () != SQLITE3) {
                File_ID (String ("New%s") % File_ID ());
            }
        }

        //---- first open processing ----

        if (first_open) {
            string name;

            num_files = 1;

            //---- print the filename ----

            if (exe->Send_Messages ()) {
                if (!part_flag) {
                    name = filename;
                } else {
                    name = pathname + ".*";
                    part_num = 0;
                }
                exe->Print_Filename (1, File_Type (), name);
            }

            //---- delete existing files ----

            if (exist_flag && part_flag) {
                int num;
                for (int part=1; part < 1000; part++) {
                    num = exe->Partition_Number (part);
                    if (num < 0) break;
                    name = pathname + Extension (num);
                    if (!f_exist (name)) break;
                    remove (name.c_str ());
                    name += ".def";
                    remove (name.c_str ());
                }
            }
        }

        if (File_Format () == SQLITE3) {
            if (sqlite3_exec (db_file, "PRAGMA synchronous = OFF", 0, 0, 0) != SQLITE_OK) {
                return (Status (NOT_OPEN));
            }
        }
        return (Status (OK));
    }
}