понедельник, 3 августа 2009 г.

Терпенью машины бывает предел

#include <Core/Core.h> 

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <io.h>

using namespace std;

string random_name()
{
string result = "";
for (int n = 0; n < 12; n++)
result += static_cast<char>(int('a')+(rand()%26));
return result;
}

bool IsAlphaString(string s)
{
bool result = true;
/*
for (int n = 0; n < s.size(); n++)
{
if (!isalnum(static_cast<int>(s[n])))
{
result = false;
break;
}
}
*/

return result;
}

CONSOLE_APP_MAIN
{
int xml_count = 1545;
//sscanf(argv[1], "%d", &xml_count);
int user_selector;

system("mkdir hub_overview");
_chdir("hub_overview");

for (user_selector = 1; user_selector <= xml_count; user_selector++)
{
printf("\rProcessing USER ID %d...", user_selector);

char Folder[128];
sprintf(Folder, "User%d", user_selector);
system((string("mkdir ")+Folder).c_str());
_chdir(Folder);

char sXML_File[256];
sprintf(sXML_File, "C:\\USER_STACK_SCANNER\\Files\\All\\%07d.xml", user_selector);
ifstream XML_File(sXML_File);
char sbuf[16384];
while (XML_File.getline(sbuf, sizeof sbuf))
{
if (strstr(sbuf, "FileListing Version") != 0)
break;
}
while (XML_File.getline(sbuf, sizeof sbuf))
{
int kind = 0;
if (strstr(sbuf, "Directory Name="))
kind = 1;
if (strstr(sbuf, "File Name="))
kind = 2;
if (strstr(sbuf, "</Directory>"))
kind = 3;
if (kind == 2)
{
string FileName = "";
{
char* pos = strstr(sbuf, "File Name=");
pos += 11;
while (*pos != '\"')
{
FileName += *pos;
pos++;
}
}
if (!IsAlphaString(FileName))
FileName = random_name();
Upp::String S = Upp::ToCharset(CHARSET_WIN1251, Upp::String(FileName), CHARSET_UTF8, 1);
FileName = Upp::to_string(S);
string MAGNET = "";
{
char* pos = strstr(sbuf, "TTH=");
pos += 5;
while (*pos != '\"')
{
MAGNET += *pos;
pos++;
}
}
string SIZE = "";
{
char* pos = strstr(sbuf, "Size=");
pos += 6;
while (*pos != '\"')
{
SIZE += *pos;
pos++;
}
}
int SIZE_MEGABYTES;
sscanf(SIZE.c_str(), "%d", &SIZE_MEGABYTES);
SIZE_MEGABYTES /=1024;
SIZE_MEGABYTES /=1024;
ofstream CurrentFile((FileName+".HTML").c_str());
CurrentFile << "<HTM>\n";
CurrentFile << "<BODY>\n";
char sttbuf[384];
sprintf(sttbuf, "<a href=\"magnet:?xt=urn:tree:tiger:%s&xl=%s&dn=%s\" title=\"%s\" target=\"_blank\">%s (%d M?)</a>", MAGNET.c_str(), SIZE.c_str(), FileName.c_str(), FileName.c_str(), FileName.c_str(), SIZE_MEGABYTES);
CurrentFile << sttbuf << endl;
CurrentFile << "</BODY>\n";
CurrentFile << "</HTM>\n";
}
else if (kind == 3)
{
_chdir("..");
}
else if (kind == 1)
{
string FolderName = "";
{
char* pos = strstr(sbuf, "Directory Name=");
pos += 16;
while (*pos != '\"')
{
FolderName += *pos;
pos++;
}
}
if (!IsAlphaString(FolderName))
FolderName = random_name();

Upp::String S = Upp::ToCharset(CHARSET_WIN1251, Upp::String(FolderName), CHARSET_UTF8, 1);
FolderName = Upp::to_string(S);

string S1 = FolderName;
FolderName = '\"' + FolderName;
FolderName += '\"';
system((string("mkdir ")+FolderName).c_str());
_chdir(S1.c_str());
}
}
_chdir("..");
}
return;
}

Комментариев нет:

Отправить комментарий