std::filesystem::path next_filename_stem_matching_pattern(const std::filesystem::path& filename_stem_pattern) { const auto filename = find_last_file_matching_pattern(filename_stem_pattern + u".*"); auto filename_stem = remove_filename_extension(filename); if( filename_stem.empty() ) { filename_stem = filename_stem_pattern; std::replace(std::begin(filename_stem), std::end(filename_stem), '?', '0'); } else { filename_stem = increment_filename_stem_ordinal(filename_stem); } return filename_stem; }
// zn_zimbra_dump zn_mailbox_p zn_zimbra_mailarchive_dumper::dump(const std::string &mailarchive) { static const size_t MAILFILE_BUF_SIZE = 4096; std::string ret; std::vector<char> buf(MAILFILE_BUF_SIZE); char *pbuf = &(buf.front()); _dump_stream.set_directory(remove_filename_extension(basename(mailarchive))); std::ifstream ifs(mailarchive.c_str(), std::ifstream::in|std::ofstream::binary); while (ifs.good()) { ifs.read(pbuf, MAILFILE_BUF_SIZE); std::string buf(pbuf, ifs.gcount()); _dump_stream << (_gunzip_stream << buf); } return _dump_stream.get_mailbox(); }
int main(int argc, char* argv[]) { int mkdir_ret = mkdir(OUTPUT_DIRECTORY, S_IRWXU); if (mkdir_ret == -1 && errno != EEXIST) error_fatal(1, "problem creating directory", strerror(errno)); else if (access(OUTPUT_DIRECTORY, W_OK | X_OK)) error_fatal(1, "Problem accessing directory", strerror(errno)); char path[500]; //No commandline arguments, so prompt for path while (argc <= 1) { printf("Enter PNG file path: "); char *s = fgets(path, 499, stdin); if (s == NULL) continue; char *newline = strrchr(s, '\n'); *newline = '\0'; FILE *f = fopen(s, "r"); if (f == NULL) { printf("Could not open file '%s'\n", s); continue; } fclose(f); argc++; argv[1] = path; //Is this out of bounds? } for (int i=1;i<argc;i++) { char *file_path = argv[i]; FILE *f = fopen(file_path, "rb"); if (f == NULL) { printf("Cannot open file '%s'\n", file_path); continue; } unsigned char* png_buf = calloc(1, 1); PNG_LENGTH = get_file_buf(f, &png_buf); printf("Glitching file '%s' (%.2lfM)\n", file_path, PNG_LENGTH / 1024.0 / 1024.0); if (PNG_LENGTH <= 0) { printf("File '%s' is empty!\n", file_path); free(png_buf); continue; } file_path = basename(file_path); remove_filename_extension(file_path); //png_buf is passed around to callbacks for libpng, it will be free'd there begin(file_path, png_buf, PNG_LENGTH); fclose(f); } return 0; }