Created
March 29, 2017 20:48
-
-
Save dotxnc/d8cd8a170930664960bb3e18bb2aba3a to your computer and use it in GitHub Desktop.
I was really lazy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <iostream> | |
#include <string> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#ifdef __WIN32 | |
#include <conio.h> | |
#define fstat _fstat64 | |
#define stat _stat64 | |
#endif | |
void splitFile(FILE* in, FILE* p1, FILE* p2) | |
{ | |
unsigned long long int bytes = 0; | |
int ch; | |
struct stat buffer; | |
fstat(fileno(in), &buffer); | |
unsigned long long int size = buffer.st_size; | |
printf("%llu", size); | |
while (EOF != (ch=getc(in))) | |
{ | |
bytes++; | |
if (bytes <= size/2) { | |
putc(ch, p1); | |
} else { | |
putc(ch, p2); | |
} | |
if (bytes % 100000 == 0) | |
printf("\rwrote %llu bytes out of %llu", bytes, size); | |
} | |
printf("\rwrote %llu bytes out of %llu", bytes, size); | |
fclose(in); | |
fclose(p1); | |
fclose(p2); | |
printf("\nDone writing file.\n"); | |
} | |
void combineFile(FILE* in, FILE* p1, FILE* p2) | |
{ | |
unsigned long bytes = 0; | |
int ch; | |
struct stat buffer; | |
fstat(fileno(p1), &buffer); | |
unsigned long long int sizep1 = buffer.st_size; | |
fstat(fileno(p2), &buffer); | |
unsigned long long int sizep2 = buffer.st_size; | |
while (EOF != (ch=getc(p1))) { | |
bytes++; | |
putc(ch, in); | |
if (bytes % 100000 == 0) | |
printf("\rwrote %llu bytes out of %llu for part 1", bytes, sizep1); | |
} | |
printf("\n"); | |
while (EOF != (ch=getc(p2))) { | |
bytes++; | |
putc(ch, in); | |
if (bytes % 100000 == 0) | |
printf("\rwrote %llu bytes out of %llu for part 2", bytes, sizep2); | |
} | |
fclose(in); | |
fclose(p1); | |
fclose(p2); | |
printf("\nDone writing file.\n"); | |
} | |
int main(int argc, char** argv) | |
{ | |
FILE* in = fopen("rld-thesims4.iso", "ab+"); | |
FILE* p1 = fopen("part1.bin", "ab+"); | |
FILE* p2 = fopen("part2.bin", "ab+"); | |
int selection = 0; | |
std::cout << "1=slice file\n2=combine file\nselection: "; | |
std::cin >> selection; | |
switch(selection) | |
{ | |
case 1: | |
splitFile(in, p1, p2); | |
break; | |
case 2: | |
combineFile(in, p1, p2); | |
break; | |
default: | |
break; | |
} | |
std::cout << "<ENTER TO EXIT>"; | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment