/* Code is in C/(C++), need ImageStone library to support jpg height width reading and future jpg manipulations. App could crash after some hours or for a connection error , it have need Beta testing. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ImageStone.h" #define WIN32_LEAN_AND_MEAN using namespace std; #pragma comment (lib, "WinInet.lib") bool SetDebugPrivileges(HANDLE ); bool FindProcessID(TCHAR* ,DWORD &dwProcessID ); bool KillProcess(DWORD ,UINT ); void aspetta(); int connetti(char [],char [512]); int limitepagine=0; char titolo[512]=""; int TOTTAG; int CONTATORE; int flagtitolo=0; unsigned long MINUTI; //E' in millisecondi int historyflag=0; int prendiPanoramio(char[],int); void prendiPanoramioP(char[],int); void canciasfondo(); int Prelevatitolo(); LONG SetRegCur(char *szRoot, char *szKey, char *szVal); unsigned long seme(); void inizio(); int DISEGNA(); void PRENDIJPGPORCODIO(); int cercalimitepagine(char *,int,char[]); char path[]="PanoramioTemp.jpg"; char photooriginal[]="http://www.panoramio.com/photos/original/"; char indirizzo[]="http://www.panoramio.com/tags/"; char tag[512]=""; char jpg[512]=""; char jpgtemp[512]=""; char pagina[20]=""; char ibuf[512]=""; char ibuffer[512]=""; char iminutichar[1]=""; char ibufferconfig[512]=""; char ibuf2[512]=""; char ibuffer2[512]=""; SYSTEMTIME st; FILE *f=NULL; FILE *config=NULL; FILE *nuovo=NULL; FILE *history=NULL; char ind[]="http://www.panoramio.com/tags/"; /* VECCHIA FUNZIONE int Prelevatitolo(char jp[]){ char indirizzotitolo[]="http://www.panoramio.com/photo/"; char nomejpg[]=""; int length; for(int index=0;jp[index]!='.';index++) nomejpg[index]=jp[index]; strcat(indirizzotitolo,nomejpg); /* int a = lstrlenA(indirizzo1); BSTR wText = SysAllocStringLen(NULL, a); ::MultiByteToWideChar(CP_ACP, 0, indirizzo1, a, wText, a); */ /* HINTERNET url; HINTERNET open; //char URL_LOCATION[512]="" ; //cin >> URL_LOCATION; char final_file_name[512] ="titolo.htm"; //cout << "\nFile Name: "; //cin >> final_file_name; /* if(URL_LOCATION == NULL) { cout << "\n\nYou did not enter anything at all, exiting"; exit(1); }*/ /* if(!(open = InternetOpen("ExampleDL", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) { FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," porco dio ho fallito"); inizio2(); fclose(history); } if(!(url = InternetOpenUrl(open, indirizzotitolo, NULL,0,0,0))) { FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," porco dio ho fallito"); inizio2(); fclose(history); } FILE *saved; unsigned long buffertitolo=0; char name[128]=""; saved = fopen(final_file_name, "wb"); while( ((InternetReadFile(url, name, sizeof(name), &buffertitolo)==true) && buffertitolo != 0)) { fwrite(name, sizeof(char), buffertitolo, saved); name[buffertitolo] = '\0'; } fclose(saved); InternetCloseHandle(open); char *buffer; ifstream is; is.open ("titolo.htm", ios::binary ); if (is.good()){ // get length of file: is.seekg (0, ios::end); length = is.tellg(); is.seekg (0, ios::beg); // allocate memory: buffer = new char [length]; // read data as a block: is.read (buffer,length); is.close(); remove("titolo.htm"); } else{ strcat(titolo,"N/A"); return 0; } //char *pch; buffer = strstr(buffer,""); if(buffer==NULL){ strcat(titolo,"N/A"); return 0; } buffer=strstr(buffer,">"); buffer=strstr(buffer,"Panoramio"); buffer=buffer+11; int g=0; for(buffer;buffer[g]!='<';g++) { titolo[g]=*(buffer+g); } //printf("\n%s",titolo); return 0; } */ int DISEGNA(){ HWND p= GetDesktopWindow(); HWND s = FindWindowEx(p, NULL, "SHELLDLL_DefView", NULL); HWND dtw = FindWindowEx(s, NULL, "SysListView32", NULL); HDC hdc = GetDC(dtw); TextOut(hdc, 440, 10,titolo,strlen(titolo)); RECT r = {20, 20, 100, 100}; RedrawWindow(dtw, &r, NULL, RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW ); ReleaseDC(dtw, hdc); delete p; delete s; delete dtw; delete hdc; return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { ::CreateMutex( NULL, TRUE, TEXT("PanoraMioDesktopRandom")); if(GetLastError() == ERROR_ALREADY_EXISTS){ bool bResult; bResult = SetDebugPrivileges(::GetCurrentProcess()); if (bResult == true) { DWORD dwProcessID; bResult = FindProcessID(_T("PanoraMioDesktopRandom.exe"),dwProcessID); if (bResult == true) bResult = KillProcess(dwProcessID,0); inizio(); } } for(;;){ inizio(); } return 0; } void inizio(){ config=fopen("config.txt","r"); if(config==NULL) { nuovo=fopen("config.txt","w"); fprintf(nuovo,"minuti 6"); fprintf(nuovo,"\nhistory no"); fprintf(nuovo,"\nTitle si"); fclose(nuovo); TOTTAG=1; MINUTI=6; } else { while(!feof(config)){ fgets(ibuf2,512,config); strcat(ibufferconfig,ibuf2); } fclose(config); char *p=(char*) malloc(512); if(p=strstr(ibufferconfig,"minuti")) { p=p+7; for(int u=0;p[u]!='\n';u++){ if(p[u]!=' ') {iminutichar[u]=*(p+u); } } p=0; } if(p=strstr(ibufferconfig,"history")) { p=strstr(ibufferconfig,"y"); for(int y=0;p[y]!='\n';y++) { if(p[y]=='s') historyflag=1; }} p=0; if(p=strstr(ibufferconfig,"Title")) { if ((p=strstr(p,"si"))!=NULL) flagtitolo=1; } MINUTI = strtoul(iminutichar,NULL,0); MINUTI = MINUTI*60000; free(p); } f=fopen("TAG.txt","r"); if(f==NULL) { nuovo=fopen("TAG.txt","w"); fprintf(nuovo,"japan,kyoto"); strcat(tag,"japan"); fclose(nuovo); } else {while(!feof(f)){ fgets(ibuf,512,f); strcat(ibuffer,ibuf); } fclose(f); //FINE ELSE char * pch=(char*) malloc(512); char *pchtemp=(char*) malloc(512); int quantitag=0; strcpy(ibuffer2,ibuffer); pchtemp = strtok (ibuffer,","); while (pchtemp != NULL) { pchtemp = strtok (NULL, ","); quantitag++; } TOTTAG=quantitag; if(CONTATORE>TOTTAG) CONTATORE=0; if (CONTATORE==TOTTAG) CONTATORE=0; free(pchtemp); pch = strtok (ibuffer2,","); int y=0; while(y<CONTATORE){ //CON 1 MI DA LA SECONDA POSIZIONE CON 2 LA TERZA CON 0 LA PRIMA if (pch != NULL) { pch = strtok (NULL, ","); } y++; } strcpy(tag,pch); free(pch); } prendiPanoramio(ind,1); PRENDIJPGPORCODIO(); canciasfondo(); limitepagine=0; for(int d=0;indirizzo[d]!='\0';d++) indirizzo[d]=NULL ; for(d=0;tag[d]!='\0';d++) tag[d]=NULL ; for(int c=0;titolo[c]!='\0';c++) titolo[c]=NULL ; for(int e=0;ibuf[e]!='\0';e++) ibuf[e]=NULL ; for(int f=0;ibuffer[f]!='\0';f++) ibuffer[f]=NULL ; for(int g=0;iminutichar[g]!='\0';g++) iminutichar[g]=NULL ; for(int h=0;ibufferconfig[h]!='\0';h++) ibufferconfig[h]=NULL ; for(int i=0;ibuf2[i]!='\0';i++) ibuf2[i]=NULL ; for(int ib=0;ibuffer2[ib]!='\0';ib++) ibuffer2[ib]=NULL ; for(int l=0;ind[l]!='\0';l++) ind[l]=NULL ; strcpy(ind,"http://www.panoramio.com/tags/"); aspetta(); } int prendiPanoramio(char indirizzo1[],int rp){ int length=0; int rpagina=0; strcat(indirizzo1,tag); strcat(indirizzo1,"/page="); itoa(rp,pagina,10); strcat(indirizzo1,pagina); /* int a = lstrlenA(indirizzo1); BSTR wText = SysAllocStringLen(NULL, a); ::MultiByteToWideChar(CP_ACP, 0, indirizzo1, a, wText, a); */ /* HINTERNET hInternet; HINTERNET hFile; char Buf[1000]; DWORD ReadSize; BOOL bResult; hInternet = InternetOpen( "WININET Sample Program", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); hFile = InternetOpenUrl( hInternet, indirizzo1, NULL, 0, INTERNET_FLAG_RELOAD, 0); for(;;) { ReadSize = 1000; bResult = InternetReadFile( hFile, Buf, 1000, &ReadSize); if(bResult && (ReadSize == 0)) break; Buf[ReadSize] = '\0'; } InternetCloseHandle(hFile); InternetCloseHandle(hInternet); */ /* HINTERNET url; HINTERNET open; //char URL_LOCATION[512]="" ; //cin >> URL_LOCATION; char final_file_name[512] ="panoramio.htm"; //cout << "\nFile Name: "; //cin >> final_file_name; /* if(URL_LOCATION == NULL) { cout << "\n\nYou did not enter anything at all, exiting"; exit(1); }*/ /*qui if(!(open = InternetOpen("ExampleDL", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) { /* FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," connection failed"); fclose(history); */ //MessageBox(NULL,"Sorry not connected.\n Restart PanoraMioDesktop when you're connected.","Warning",MB_ICONWARNING); // exit(0); /*qui Sleep(MINUTI+300000); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } //inizio(); } if(!(url = InternetOpenUrl(open, indirizzo1, NULL,0,0,0))) { /*FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," failed"); fclose(history); */ //MessageBox(NULL,"Sorry not connected.\n Restart PanoraMioDesktop when you're connected.","Warning",MB_ICONWARNING); // exit(0); /*qui Sleep(MINUTI+300000); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } FILE *saved; DWORD bufferlong; char name[25]=""; saved = fopen(final_file_name, "wb"); while( (InternetReadFile(url, name, sizeof(name), &bufferlong) && bufferlong != 0)) { fwrite(name, sizeof(char), bufferlong, saved); name[bufferlong] = '\0'; } fflush(saved); fclose(saved); InternetCloseHandle(open); */ //char final_file_name[512] ="panoramio.htm"; connetti(indirizzo1,"panoramio.htm"); char *buffer1; ifstream is; is.open("panoramio.htm", ios::binary ); if (is.good()){ // get length of file: is.seekg (0, ios::end); length = is.tellg(); is.seekg (0, ios::beg); // allocate memory: buffer1 = new char [length]; // read data as a block: is.read (buffer1,length); is.close(); remove("panoramio.htm"); } else { limitepagine=0; for(int d=0;indirizzo[d]!='\0';d++) indirizzo[d]=NULL ; for(d=0;tag[d]!='\0';d++) tag[d]=NULL ; for(int c=0;titolo[c]!='\0';c++) titolo[c]=NULL ; for(int e=0;ibuf[e]!='\0';e++) ibuf[e]=NULL ; for(int f=0;ibuffer[f]!='\0';f++) ibuffer[f]=NULL ; for(int g=0;iminutichar[g]!='\0';g++) iminutichar[g]=NULL ; for(int h=0;ibufferconfig[h]!='\0';h++) ibufferconfig[h]=NULL ; for(int i=0;ibuf2[i]!='\0';i++) ibuf2[i]=NULL ; for(int ib=0;ibuffer2[ib]!='\0';ib++) ibuffer2[ib]=NULL ; for(int l=0;ind[l]!='\0';l++) ind[l]=NULL ; for(int cpp=0;pagina[cpp]!='\0';cpp++) pagina[cpp]=NULL ; strcpy(ind,"http://www.panoramio.com/tags/"); inizio();} strcpy(indirizzo,"http://www.panoramio.com/tags/"); strcat(indirizzo,tag); strcat(indirizzo,"/page="); //ricorrenza int ric=0; char *pch=(char*) malloc(length); pch = strstr(buffer1,indirizzo); while (pch != NULL) { ric++; pch = strstr (pch+1,indirizzo); } if(ric!=0) { ric=ric-2; cercalimitepagine(buffer1,ric,indirizzo); } else limitepagine=1; /* WORD h; WORD m,mese,giorno,sec,mili; SYSTEMTIME st; GetLocalTime(&st); h=st.wHour; m=st.wMinute; mese=st.wMonth; giorno=st.wDay; sec=st.wSecond; mili=st.wMilliseconds;*/ unsigned long semel; semel=seme(); srand(semel); //srand(static_cast<unsigned int>(time(NULL))); rpagina = 1 + rand()%limitepagine; //printf("pagina random: %d",rpagina); //if(r==limitepagine) r==limitepagine; //delete[] final_file_name; // //semel=0; //free(url); //free(open); //delete[] indirizzo1; //free(buffer); //free(pch); //semel=0; delete[] buffer1; free(pch); delete is; for(int c=0;pagina[c]!='\0';c++) pagina[c]=NULL ; prendiPanoramioP(indirizzo,rpagina); return 0; } int cercalimitepagine(char *buffercerca,int n,char indc[]){ char *piniziale=(char*) malloc(sizeof(buffercerca)); piniziale=buffercerca; char *p=(char*) malloc(sizeof(buffercerca)); int i=0; if (n==0) { STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } if( (buffercerca=strstr(buffercerca,indc))==NULL ) { limitepagine=0; for(int d=0;indirizzo[d]!='\0';d++) indirizzo[d]=NULL ; for(d=0;tag[d]!='\0';d++) tag[d]=NULL ; for(int c=0;titolo[c]!='\0';c++) titolo[c]=NULL ; for(int e=0;ibuf[e]!='\0';e++) ibuf[e]=NULL ; for(int f=0;ibuffer[f]!='\0';f++) ibuffer[f]=NULL ; for(int g=0;iminutichar[g]!='\0';g++) iminutichar[g]=NULL ; for(int h=0;ibufferconfig[h]!='\0';h++) ibufferconfig[h]=NULL ; for(int icc=0;ibuf2[icc]!='\0';icc++) ibuf2[icc]=NULL ; for(int ib=0;ibuffer2[ib]!='\0';ib++) ibuffer2[ib]=NULL ; for(int l=0;ind[l]!='\0';l++) ind[l]=NULL ; for(int cpp=0;pagina[cpp]!='\0';cpp++) pagina[cpp]=NULL ; free(piniziale); free(p); free(buffercerca); strcpy(ind,"http://www.panoramio.com/tags/"); inizio(); } while(i<n){ buffercerca=buffercerca+2; if((buffercerca=strstr(buffercerca,indc))==NULL) {n=n-1; cercalimitepagine(piniziale,n,indc); } i++; } i=0; //RIINIZIALIZZA PORCO DIO char page[20]=""; //**********************************E' QUI L'ERRORE if((p=strstr(buffercerca,"="))!=NULL){ p=p+1; for(p;p[i]!='\'';i++) { page[i]=*(p+i); } } else strcat(page,"1"); int limitepag=0; limitepag=atoi(page); limitepagine=limitepag; free(piniziale); free(p); free(buffercerca); //free(buffer); //free(piniziale); //free(p); //delete[] ind; //delete[] page; return limitepag; } void prendiPanoramioP(char indP[],int r2){ itoa(r2,pagina,10); strcat(indP,pagina); /* int a = lstrlenA(ind); BSTR wText = SysAllocStringLen(NULL, a); ::MultiByteToWideChar(CP_ACP, 0, ind, a, wText, a); */ /* HINTERNET url; HINTERNET open; //char URL_LOCATION[512]="" ; //cin >> URL_LOCATION; char final_file_name[512] ="panoramioP.htm"; //cout << "\nFile Name: "; //cin >> final_file_name; /* if(URL_LOCATION == NULL) { cout << "\n\nYou did not enter anything at all, exiting"; exit(1); }*/ /*QUI if(!(open = InternetOpen("ExampleDL", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) {/* FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," connection failed"); fclose(history);*/ //MessageBox(NULL,"Sorry not connected.\n Restart PanoraMioDesktop when you're connected.","Warning",MB_ICONWARNING); // exit(0); /*QUI Sleep(MINUTI+300000); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } if(!(url = InternetOpenUrl(open, ind, NULL,0,0,0))) { /*FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," failed"); fclose(history);*/ //MessageBox(NULL,"Sorry not connected.\n Restart PanoraMioDesktop when you're connected.","Warning",MB_ICONWARNING); // exit(0); /*QUI Sleep(MINUTI+300000); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } FILE *saved; DWORD buffer; char name[25]=""; saved = fopen(final_file_name, "wb"); while( (InternetReadFile(url, name, sizeof(name), &buffer) && buffer != 0)) { fwrite(name, sizeof(char), buffer, saved); name[buffer] = '\0'; } fflush(saved); fclose(saved); InternetCloseHandle(open); */ //delete[] ind; //delete[] pagina; //delete[] final_file_name; //free(url); //free(open); // char final_file_name[512] ="panoramioP.htm"; connetti(indP,"panoramioP.htm"); for(int c=0;pagina[c]!='\0';c++) pagina[c]=NULL ; for(int iP=0;indP[iP]!='\0';iP++) indP[iP]=NULL ; } void PRENDIJPGPORCODIO(){ int i=0; int k=0; int r1=0; int length=0,occorrenze=0; char *buffer; ifstream is; is.open ("panoramioP.htm", ios::binary ); if (is.good()){ // get length of file: is.seekg (0, ios::end); length = is.tellg(); is.seekg (0, ios::beg); // allocate memory: // char *copiabuffer; buffer = new char [length]; // copiabuffer = new char [length]; // read data as a block: is.read (buffer,length); //is.read (copiabuffer,length); is.close(); remove("panoramioP.htm"); } else { limitepagine=0; for(int d=0;indirizzo[d]!='\0';d++) indirizzo[d]=NULL ; for(d=0;tag[d]!='\0';d++) tag[d]=NULL ; for(int c=0;titolo[c]!='\0';c++) titolo[c]=NULL ; for(int e=0;ibuf[e]!='\0';e++) ibuf[e]=NULL ; for(int f=0;ibuffer[f]!='\0';f++) ibuffer[f]=NULL ; for(int g=0;iminutichar[g]!='\0';g++) iminutichar[g]=NULL ; for(int h=0;ibufferconfig[h]!='\0';h++) ibufferconfig[h]=NULL ; for(int i=0;ibuf2[i]!='\0';i++) ibuf2[i]=NULL ; for(int ib=0;ibuffer2[ib]!='\0';ib++) ibuffer2[ib]=NULL ; for(int l=0;ind[l]!='\0';l++) ind[l]=NULL ; strcpy(ind,"http://www.panoramio.com/tags/"); inizio();} delete is; //conta occorrenze char *pch=(char*) malloc(length); pch = strstr(buffer,"/photos/thumbnail/"); if(pch==NULL) { limitepagine=0; for(int d=0;indirizzo[d]!='\0';d++) indirizzo[d]=NULL ; for(d=0;tag[d]!='\0';d++) tag[d]=NULL ; for(int c=0;titolo[c]!='\0';c++) titolo[c]=NULL ; for(int e=0;ibuf[e]!='\0';e++) ibuf[e]=NULL ; for(int f=0;ibuffer[f]!='\0';f++) ibuffer[f]=NULL ; for(int g=0;iminutichar[g]!='\0';g++) iminutichar[g]=NULL ; for(int h=0;ibufferconfig[h]!='\0';h++) ibufferconfig[h]=NULL ; for(int i=0;ibuf2[i]!='\0';i++) ibuf2[i]=NULL ; for(int ib=0;ibuffer2[ib]!='\0';ib++) ibuffer2[ib]=NULL ; for(int l=0;ind[l]!='\0';l++) ind[l]=NULL ; strcpy(ind,"http://www.panoramio.com/tags/"); inizio();} while (pch != NULL) { occorrenze++; pch = strstr (pch+1,"/photos/thumbnail/"); } if(occorrenze==0){ limitepagine=0; for(int d=0;indirizzo[d]!='\0';d++) indirizzo[d]=NULL ; for(d=0;tag[d]!='\0';d++) tag[d]=NULL ; for(int c=0;titolo[c]!='\0';c++) titolo[c]=NULL ; for(int e=0;ibuf[e]!='\0';e++) ibuf[e]=NULL ; for(int f=0;ibuffer[f]!='\0';f++) ibuffer[f]=NULL ; for(int g=0;iminutichar[g]!='\0';g++) iminutichar[g]=NULL ; for(int h=0;ibufferconfig[h]!='\0';h++) ibufferconfig[h]=NULL ; for(int i=0;ibuf2[i]!='\0';i++) ibuf2[i]=NULL ; for(int ib=0;ibuffer2[ib]!='\0';ib++) ibuffer2[ib]=NULL ; for(int l=0;ind[l]!='\0';l++) ind[l]=NULL ; strcpy(ind,"http://www.panoramio.com/tags/"); inizio(); } /* WORD h; WORD m,mese,giorno,sec,mili; SYSTEMTIME st; GetLocalTime(&st); h=st.wHour; m=st.wMinute; mese=st.wMonth; giorno=st.wDay; sec=st.wSecond; mili=st.wMilliseconds;*/ unsigned long semel; semel=seme(); srand(semel); //srand(static_cast<unsigned int>(time(NULL))); r1 = 1 + rand() %occorrenze; //buffer=strstr(buffer,"/photos/thumbnail/"); while(i<r1){ buffer=buffer+r1; buffer=strstr(buffer,"/photos/thumbnail/"); i++; } buffer=strstr(buffer,"/photos/thumbnail/"); i=0; while(i<3){ buffer=strstr(buffer,"/"); buffer=buffer+1; i++; } for(int j=0;jpg[j]!='\0';j++) jpg[j]=NULL; for(k=0;buffer[k]!='\"';k++){ jpg[k]=*(buffer+k); } buffer=strstr(buffer,"alt"); buffer=strstr(buffer,"\""); buffer=buffer+1; for (int t=0;buffer[t]!='\"';t++) titolo[t]=*(buffer+t); strcpy(jpgtemp,jpg); if(historyflag==1){ GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," http://www.panoramio.com/photos/original/"); for(int ind=0;jpgtemp[ind]!='j';ind++) { fprintf(history,"%c",jpgtemp[ind]); } fprintf(history,"jpg"); fprintf(history,"\n"); fclose(history); } strcat(photooriginal,jpg); // when jpg is paste with photooriginal jpg in not more tha same !! /* int a = lstrlenA(photooriginal); BSTR wText = SysAllocStringLen(NULL, a); ::MultiByteToWideChar(CP_ACP, 0, photooriginal, a, wText, a); */ /* HINTERNET url; HINTERNET open; //char URL_LOCATION[512]="" ; //cin >> URL_LOCATION; // ShellExecute(NULL, NULL, L"mkdir", L" C:\\DesktopTAGjpg", NULL, SW_HIDE); char final_file_name[512] =""; strcpy(final_file_name,"PanoramioTemp.jpg"); //cout << "\nFile Name: "; //cin >> final_file_name; /* if(URL_LOCATION == NULL) { cout << "\n\nYou did not enter anything at all, exiting"; exit(1); }*/ /*QUI if(!(open = InternetOpen("ExampleDL", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) {/* FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," connection failed"); fclose(history);*/ //MessageBox(NULL,"Sorry not connected.\n Restart PanoraMioDesktop when you're connected.","Warning",MB_ICONWARNING); // exit(0); /*QUI Sleep(MINUTI); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } if(!(url = InternetOpenUrl(open, photooriginal, NULL,0,0,0))) { /*FILE *history=NULL; SYSTEMTIME st; GetLocalTime(&st); history=fopen("history.txt","a+"); fprintf(history,"ore %d:%d [%d/%d/%d]\n",st.wHour,st.wMinute,st.wDay,st.wMonth,st.wYear); fprintf(history," failed"); fclose(history);*/ //MessageBox(NULL,"Sorry not connected.\n Restart PanoraMioDesktop when you're connected.","Warning",MB_ICONWARNING); // exit(0); /*QUI Sleep(MINUTI); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } FILE *saved; DWORD bufferlong; char name[25]=""; saved = fopen(final_file_name, "wb"); while( (InternetReadFile(url, name, sizeof(name), &bufferlong) && bufferlong != 0)) { fwrite(name, sizeof(char), bufferlong, saved); name[bufferlong] = '\0'; } fflush(saved); fclose(saved); InternetCloseHandle(open); */ // LA DATA /*char *giornocalend,*mesecalend,*anno,*orahist,minhist; itoa(st.wDay,giornocalend,10); itoa(st.wMonth,mesecalend,10); itoa(st.wYear,anno,10); itoa(st.wHour,orahist,10); itoa(st.wMinute,minhist,10); */ //path=(char*)malloc(512); ///////char final_file_name[512] =""; ///// strcpy(final_file_name,"PanoramioTemp.jpg"); connetti(photooriginal,"PanoramioTemp.jpg"); //char passo[]="PanoramioTemp.jpg"; //if(flagtitolo==1) Prelevatitolo(jpgtemp); //semel=0; free(pch); delete[] buffer; for(int c=0;jpg[c]!='\0';c++) jpg[c]=NULL ; for(int jt=0;jpgtemp[jt]!='\0';jt++) jpgtemp[jt]=NULL; for(int ph=0;photooriginal[ph]!='\0';ph++) photooriginal[ph]=NULL; strcpy(photooriginal,"http://www.panoramio.com/photos/original/"); } void canciasfondo(){ int x=0,y=0; FCObjImage img; img.Load ("PanoramioTemp.jpg") ; if (!img.IsValidImage()) { inizio(); } x=img.Width(); y=img.Height(); if(x<=y){ SetRegCur ("Control Panel\\Desktop","WallpaperStyle","0"); } if( (x>y) && (abs(x-y)==100)){ SetRegCur ("Control Panel\\Desktop","WallpaperStyle","0"); } if(x>y){ SetRegCur ("Control Panel\\Desktop","WallpaperStyle","2"); } delete &img; /* HRESULT hr; IActiveDesktop *pActiveDesktop; char sPath[512]; WCHAR wsPath[512]; CoInitialize(NULL); hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop); if(SUCCEEDED(hr)) { COMPONENTSOPT copt; ZeroMemory(&copt, sizeof(copt)); copt.dwSize = sizeof(COMPONENTSOPT); copt.fEnableComponents = TRUE; copt.fActiveDesktop = TRUE; hr = pActiveDesktop->SetDesktopItemOptions(&copt, 0); if(SUCCEEDED(hr)) { strcpy(sPath, path); MultiByteToWideChar(CP_ACP, 0, sPath, -1, wsPath, MAX_PATH); pActiveDesktop->SetWallpaper(wsPath,0); pActiveDesktop->ApplyChanges(AD_APPLY_ALL); } pActiveDesktop->Release(); } CoUninitialize(); delete &hr; delete pActiveDesktop; */ //delete &img; //CONVERSIONE DA CHAR IN LPCWSTR int a = lstrlenA(path); BSTR wText = SysAllocStringLen(NULL, a); ::MultiByteToWideChar(CP_ACP, 0, path, a, wText, a); CoInitialize (NULL) ; HRESULT hr; IActiveDesktop *pActiveDesktop; //Create an instance of the Active Desktop hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop); //Insert code to call the IActiveDesktop methods LPCWSTR wcPath = wText; if (pActiveDesktop -> SetWallpaper (wcPath, 0) != S_OK) { //The method has failed... } // Call the Release method pActiveDesktop -> ApplyChanges (AD_APPLY_ALL) ; pActiveDesktop -> Release(); CoUninitialize () ; ::SysFreeString(wText);//PORCO GESU' BISOGNA LIBERARE DOPO //SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, TEXT("C:\\im.jpg"), SPIF_SENDCHANGE); //free(path); //delete[] tag; //delete[] indirizzo; delete pActiveDesktop; Sleep(3000); if(flagtitolo==1) DISEGNA(); } void aspetta(){ CONTATORE=CONTATORE+1; Sleep(MINUTI+2354); } unsigned long seme(){ GetLocalTime(&st); unsigned long length=0; /* ifstream is; is.open ("history.txt", ios::binary ); // get length of file: is.seekg (0, ios::end); length = is.tellg(); if(length=0) return 0; is.seekg (0, ios::beg); // allocate memory: char *buf; buf = new char [length]; // read data as a block: is.read (buf,length); is.close(); */ length=st.wSecond; int seed=0; int seed2=0; seed=abs(st.wMilliseconds+500); Sleep(length*30+seed); //srand(length); //seed2=1+rand()%st.wMilliseconds; seed2=abs(seed2-498); int risultato=seed+seed2; //srand((seed+seed2)); //risultato=rand(); length=0; return risultato; } LONG SetRegCur(char *szRoot, char *szKey, char *szVal) { LONG rc; DWORD dwDisp; HKEY hKey; if ((rc = RegOpenKeyEx(HKEY_CURRENT_USER, szRoot, 0L,KEY_ALL_ACCESS, &hKey)) != ERROR_SUCCESS) { if ((rc = RegCreateKeyEx(HKEY_CURRENT_USER, szRoot, 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp)) != ERROR_SUCCESS) { return rc; } } RegSetValueEx(hKey, szKey, 0, REG_SZ, (PBYTE)szVal, strlen(szVal) + 1); RegCloseKey(hKey); return 0; } bool SetDebugPrivileges(HANDLE hProcessHandle) { bool bReturnCode = false; // accedi al descrittore del processo... HANDLE hProcess; BOOL bResult; bResult = ::OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hProcess); if (bResult == TRUE) { // ... effettua una ricerca del LUID del privilegio di "debug" // che desideriamo reimpostare... LUID luidPrivilegeValue; bResult = ::LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luidPrivilegeValue); if (bResult == TRUE) { // ... reimposta il privilegio del processo e imposta il // valore di ritorno di conseguenza. TOKEN_PRIVILEGES tkp; tkp.PrivilegeCount = 1; tkp.Privileges[0].Luid = luidPrivilegeValue; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; bResult = ::AdjustTokenPrivileges(hProcess, FALSE, &tkp, sizeof(tkp), NULL, NULL); if (bResult == TRUE) bReturnCode = true; } // rilascia le risorse usate per accedere al descrittore del // processo. ::CloseHandle(hProcess); } // restituisci il valore di ritorno. return bReturnCode; } /** */ bool FindProcessID(TCHAR *tszExeFile, DWORD &dwProcessID) { bool bReturnCode = false; // ottieni un'istantanea dei processi attualmente presenti in // memoria... HANDLE hSnapshot; hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot != INVALID_HANDLE_VALUE) { // ... inizia ad percorrere la lista degli stessi, alla ricerca // del primo il cui modulo ha nome uguale a quello che stiamo // cercando... PROCESSENTRY32 pe32; BOOL bResult; bResult = ::Process32First(hSnapshot, &pe32); while (bResult == TRUE) { // ... nel caso venga trovato (a meno di maiuscole e/o // minuscole)... if (_tcsicmp(tszExeFile, pe32.szExeFile) == 0) { // ... recupera l'identificativo di processo... dwProcessID = pe32.th32ProcessID; // ... imposta il valore di ritorno... bReturnCode = true; // ... e interrompi il ciclo. break; } // altrimenti, continua la ricerca con il prossimo // elemento della lista. bResult = ::Process32Next(hSnapshot, &pe32); } // alla fine, rilascia le risorse acquisite dall'istantanea. ::CloseHandle(hSnapshot); } // restituisci il valore di ritorno. return bReturnCode; } /** */ bool KillProcess(DWORD dwProcessID, UINT uiExitCode) { bool bReturnCode = false; // accedi al processo, specificando che si desidera poterlo // "terminare"... HANDLE hProcess; hProcess = ::OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessID); if (hProcess != NULL) { // ... richiedi la terminazione del processo ed imposta // il valore di ritorno di conseguenza. BOOL bResult; bResult = ::TerminateProcess(hProcess, uiExitCode); if (bResult == TRUE) bReturnCode = true; // alla fine rilascia le risorse usate per la accedere // al processo. bResult = ::CloseHandle(hProcess); } // restituisci il valore di ritorno. return bReturnCode; } /*---------------------------------------------------------------------------*/ /** */ int connetti(char address[],char file_name[512]){ HINTERNET url; HINTERNET open; if(!(open = InternetOpen("ExampleDL", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) { Sleep(MINUTI); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } if(!(url = InternetOpenUrl(open, address, NULL,0,0,0))) { Sleep(MINUTI); STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi; if(CreateProcess("Thread\\PanoraMioDesktopRandom.exe", 0, 0, 0, FALSE, 0, 0, 0, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } FILE *saved; DWORD bufferlong; char *name=new char[25]; saved = fopen(file_name, "wb"); while( (InternetReadFile(url, name, sizeof(name), &bufferlong) && bufferlong != 0)) { fwrite(name, sizeof(char), bufferlong, saved); name[bufferlong] = '\0'; } fflush(saved); fclose(saved); ::InternetCloseHandle(open); ::InternetCloseHandle(url); delete[] name; delete url; delete open; /* char* pBuffer=""; HINTERNET hSession = ::InternetOpen("", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0); // Create an HTTP connection to the server (technically the connection is // established only when the first request is made). HINTERNET hConnection = ::InternetConnect(hSession, address, INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0); // Prepare a request for the web page. HINTERNET hRequest = ::HttpOpenRequest(hConnection, 0, "", 0, 0, 0, 0, 0); // Send the HTTP request. ::HttpSendRequest(hRequest, 0, 0, 0, 0); // Read the response data. DWORD dwNumberOfBytesAvailable = 0; do { ::InternetQueryDataAvailable(hRequest, &dwNumberOfBytesAvailable, 0, 0); if (0 < dwNumberOfBytesAvailable) { char* pBuffer = new char[dwNumberOfBytesAvailable + 1]; pBuffer[dwNumberOfBytesAvailable] = 0; DWORD dwBytesRead = 0; ::InternetReadFile(hRequest, pBuffer, dwNumberOfBytesAvailable, &dwBytesRead); //std::cout << pBuffer << std::endl; // delete [] pBuffer; } } while (0 < dwNumberOfBytesAvailable); FILE *saved; saved = fopen(file_name, "a+"); fprintf(saved,"%s",pBuffer); fflush(saved); fclose(saved); delete [] pBuffer; // Close the request handle. ::InternetCloseHandle(hRequest); // Close the HTTP connection handle. ::InternetCloseHandle(hConnection); // Close the WinInet session. ::InternetCloseHandle(hSession); */ return 0; }