AMX MOD X
Вторник, 06.01.2026, 10:21:56



Приветствую Вас Гость | RSS
[ Главная ] [ Копирование файлов - AMX Mod X Форум ] [ Регистрация ] [ Вход ]
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]

Вниманию участников! Данный форум теперь является архивом и вскором времени здесь нельзя будет создавать новых тем! Просьба всем для общения и создания новых тем перейти на наш новый форум: http://amxmodx.su/

  • Страница 1 из 1
  • 1
Модератор форума: slogic, AlMod  
Копирование файлов
heorДата: Воскресенье, 13.07.2008, 10:28:13 | Сообщение # 1
Сержант
Группа: Пользователи
Сообщений: 33
Репутация: 0
Статус: Не в сети
Столкнулся с проблемой. Как в amx скопировать файл?
Суть копирования простая: читаем n байт в буффер, а потом пишем его в файл. Но не могу ее реализовать. devil
Какими функциями пользоваться ?
 
BruteДата: Воскресенье, 13.07.2008, 11:19:59 | Сообщение # 2
Генерал-полковник
Группа: Скриптеры
Сообщений: 1123
Репутация: 9
Статус: Не в сети
[code=file.inc]/* Files functions
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
* This file is provided as is (no warranties).
*/

#if defined _file_included
#endinput
#endif
#define _file_included

/* Reads content from directory.
* Returns index of next element or 0 when end of dir. is reached. */
native read_dir(const dirname[],pos,output[],len,&outlen);

/* Reads line from file. Returns index of next line or 0 when end of file is reached. */
native read_file(const file[],line,text[],len,&txtlen);

/* Writes text to file. Function returns 0 on failure.
* When line is set to -1, the text is added at the end of file. */
native write_file(const file[],const text[],line = -1);

/* Deletes file. Function returns 1 on success, 0 on failure. */
native delete_file(const file[]);

/* Checks for file. If file exists function returns 1, in other case 0. */
native file_exists(const file[]);

/* renames a file. returns 0 on failure, 1 on success.
* if relative true, rename_file will act like other natives which
* use the moddir as a base directory. otherwise, the current directory is
* undefined (but assumed to be hlds).
*/
native rename_file(const oldname[], const newname[], relative=0);

/* Checks if a directory exists */
native dir_exists(const dir[]);

/* Returns a file size in bytes if flag is set to 0.
* When flag is set to 1 returns number of lines in the file,
* and when flags is 2, function returns 1 if the file ends
* with line feed. If file doesn't exist returns -1. */
native file_size(const file[], flag=0);

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

//Open a file, returns a handle or 0 on failure
native fopen(const filename[],const mode[]);

//Closes a file handle
native fclose(file);

#define BLOCK_INT 4
#define BLOCK_SHORT 2
#define BLOCK_CHAR 1
#define BLOCK_BYTE 1

//The following functions work as such:
// RAW - means the array you pass is a raw bytestream, for experts only
// BLOCK - means you are passing in an array where each element will be written
// NORMAL - means you are writing only one element
// RAW and BLOCK return the number of blocks acted upon successfully
// NORMAL returns 1 on success

native fread(file, &data, mode);
native fread_blocks(file, data[], blocks, mode);
native fread_raw(file, stream[], blocksize, blocks);
native fwrite(file, data, mode);
native fwrite_blocks(file, const data[], blocks, mode);
native fwrite_raw(file, const stream[], blocksize, mode);

//Returns 1 if the file is ended, 0 otherwise
native feof(file);

//Reads a line from a text file -- includes newline!
native fgets(file, buffer[], maxlength);

//Writes a line to a text file. Returns # of characters written.
native fputs(file, const text[]);

//Writes a line to the file
native fprintf(file, const fmt[], any:...);

//Sets the current position in a file (see SEEK_ values above)
native fseek(file, position, start);

//Returns the current position in a file
native ftell(file);

//These are straight from the C standard.
native fgetc(file);
native fputc(file, data);
native fungetc(file, data);

//Return the size of a file
native filesize(const filename[], any:...);

//Attempts to remove a directory.
//Note that you cannot remove a directory that has files on most
// operating systems.
native rmdir(const path[]);

/* Returns 0 on success, like the POSIX specification */
native mkdir(const dirname[]);

//Delete a file (delete_file macro)
native unlink(const filename[]);

//Returns a handle to a directory
native open_dir(dir[], firstfile[], length);
native next_file(dirh, buffer[], length);
native close_dir(dirh);

/**
* Loads a file using the LoadFileForMe engine function.
*
* The data is truncated if there is not enough space. No null-terminator
* is applied; the data is the raw contents of the file.
*
* @param file File to load (may be a file from the GCF).
* @param buffer Buffer to store file contents.
* @param maxlength Maximum size of the file buffer.
* @param length Variable to store the file length. This may return
* a number larger than the buffer size.
* @return -1 if the file could not be loaded. Otherwise,
* the number of cells actually written to the buffer
* are returned.
*/
native LoadFileForMe(const file[], buffer[], maxlength, &length=0);[/code]

сори, что на английском P

 
heorДата: Воскресенье, 13.07.2008, 13:20:34 | Сообщение # 3
Сержант
Группа: Пользователи
Сообщений: 33
Репутация: 0
Статус: Не в сети
а что делают процедуры
native fread(file, &data, mode);
native fread_blocks(file, data[], blocks, mode);
native fread_raw(file, stream[], blocksize, blocks);
native fwrite(file, data, mode);
native fwrite_blocks(file, const data[], blocks, mode);
native fwrite_raw(file, const stream[], blocksize, mode);

есть ли процедура к-я позволяет прочитать буфер размером с size?
Ни одна из этих не позволяет(или я не правильно понял), а
native fread(file, &data, mode); вообще читает посимвольно !!!

 
BruteДата: Воскресенье, 13.07.2008, 21:47:47 | Сообщение # 4
Генерал-полковник
Группа: Скриптеры
Сообщений: 1123
Репутация: 9
Статус: Не в сети
Можно читать и писать блоками блоками

fread_blocks(file, data[], blocks, mode)
fwrite_blocks(file, const data[], blocks, mode)

Если файл состоит из текста будет правильно использовать
ead_file(const file[],line,text[],len,&txtlen) и write_file(const file[],const text[],line = -1)

Всё это осуществляется через циклы
вот пример чтения текстового файла:

Code
public read_txt_file(id)
{
  get_configsdir(configsdir,199)
  format(file1,199,"%s/1.txt",configsdir)

  new read[32], txtlen
  if(file_exists(file1))
  {
   for(new i=0;i<sizeof(file1);i++)
   {
    read_file(file1,i,read,31,txtlen)
    zzbuffer[id][i] = read
   }
  }
}

а вот пример записи текстового файла:
Code
public save_txt_file(id)
{
  get_configsdir(configsdir,199)
  format(file2,199,"%s/2.txt",configsdir)
  new string[32]
  for(new i=0;i<(file2);i++)
  {
   format(string,31,"%s",zzbuffer[id][i])
   write_file(file2,string,i)
  }
}


Сообщение отредактировал Brute - Воскресенье, 13.07.2008, 21:49:41
 
heorДата: Понедельник, 14.07.2008, 17:51:11 | Сообщение # 5
Сержант
Группа: Пользователи
Сообщений: 33
Репутация: 0
Статус: Не в сети
спс :)
 
  • Страница 1 из 1
  • 1
Поиск:

AMX Mod X Russian Community © 2006-2026