-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTorrentBuild_CPPFunctions.cpp
64 lines (54 loc) · 1.65 KB
/
TorrentBuild_CPPFunctions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//---------------------------------------------------------------------------
//
// Name: TorrentBuild_CPPFunctions.cpp
// Author: Harold Feit
// Created: 5/19/2006 11:09:52 AM
// Description:
//
//---------------------------------------------------------------------------
#include "atom.h"
#include "bencode.h"
#include "util.h"
#include "stringsplit.h"
#include "SHA1.h"
#include "TorrentBuild_CPPFunctions.h"
#include <cstdlib>
#include <iostream>
#include <fstream>
__int64 FileSize(const char* sFileName)
{
std::ifstream f;
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
if (!f.good() || f.eof() || !f.is_open()) { return 0; }
f.seekg(0, std::ios_base::beg);
std::ifstream::pos_type begin_pos = f.tellg();
f.seekg(0, std::ios_base::end);
return static_cast<int>(f.tellg() - begin_pos);
}
int GetAutoPieceSize ( unsigned long TotalSize )
{
int64 fiftymeg = 50*1024*1024;
int64 onefiftymeg = 150*1024*1024;
int64 threefiftymeg = 350*1024*1024;
int64 halfgig = 512*1024*1024;
int64 onegig = 1024*1024*1024;
int64 twogig = 2048*1024*1024;
if( TotalSize < fiftymeg )
return ( 32768 );
else if ( TotalSize < onefiftymeg )
return ( 65536 );
else if ( TotalSize < threefiftymeg )
return ( 131072 );
else if ( TotalSize < halfgig )
return ( 262144 );
else if ( TotalSize < onegig )
return ( 524288 );
else if ( TotalSize < twogig )
return ( 1048576 );
else
return ( 2097152 );
}
CAtom *GetConfig()
{
return DecodeFile( "tgen.configure" );
}