Пример #1
0
void INI::save_file(const chowstring & fn, bool force)
{
    if (fn.empty() || (read_only && !force))
        return;
    changed = false;
    filename = convert_path(fn);
    std::cout << "Saving: " << filename << std::endl;
    platform_create_directories(get_path_dirname(filename));
    std::stringstream out;
    get_data(out);
    chowstring outs = out.str();

    if (!encrypt_key.empty())
        encrypt_ini_data(outs, encrypt_key);

    if (use_compression) {
        compress_huffman(outs, filename.c_str());
        return;
    }

#ifdef CHOWDREN_USE_BLOWFISH_CACHE
    if (BlowfishObject::set_cache(filename, outs))
        return;
#endif

    FSFile fp(filename.c_str(), "w");
    if (!fp.is_open()) {
        std::cout << "Could not save INI file: " << filename << std::endl;
        return;
    }
	if (!outs.empty())
        fp.write(&outs[0], outs.size());
    fp.close();
}
Пример #2
0
void prepare_files(char c, int count, char* argv[]){
  int i;
  unsigned int FileSizePacked = 0, FileSizeOriginal = 0;
  FILE *fbuf, *temp;
  fbuf = fopen("temp.txt", "wb");
  for (i = 0; i < count; i++){
    temp = fopen(argv[i+1], "rb");
    Files[i].FileLength = strlen(argv[i+1]);
    Files[i].FileName = argv[i+1];
    Files[i].Attributes = 0;
    Files[i].Time_Created = 0;//__TIME__;
    Files[i].Time_Modified = 0;//__TIME__;
    Files[i].SizePacked = 0;
    Files[i].compress_file = compress_huffman(temp, &FileSizeOriginal, &FileSizePacked);
    Files[i].SizePacked = FileSizePacked;
    Files[i].SizeOriginal = FileSizeOriginal;
    FileSizePacked = 0;
    FileSizeOriginal = 0;

    if (c == 1){
      char tc;
      rewind(temp);
      while(!feof(temp)){
		if (fscanf(temp, "%c", &tc) != EOF)
          fprintf(fbuf, "%c", tc);
      }
    }

    fclose(temp);
  }
  fclose(fbuf);
  if (c == 1){
    fbuf = fopen("temp.txt", "rb");
    Files[0].compress_file = compress_huffman(fbuf, &FileSizeOriginal, &FileSizePacked);
    Files[0].SizePacked = FileSizePacked;
    FileSizePacked = 0;
    FileSizeOriginal = 0;
  }
}