summaryrefslogtreecommitdiff
path: root/protocols/Xfire/src/iniupdater.cpp
blob: dd82e010e84addf022d76e78514b5100e0132a71 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//iniupdater.cpp by dufte, großen dank an xfireplus.com

#include "stdafx.h"

#include "iniupdater.h"
#include "baseProtocol.h"
#include "variables.h"

extern HANDLE XFireWorkingFolder;
extern HANDLE XFireIconFolder;

INT_PTR CALLBACK DlgUpdateDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);

			char*buf=NULL; //leeren zeiger für den empfangen buffer
			GetWWWContent2(INI_WHATSNEW,NULL,FALSE,&buf);

			if(buf!=NULL)
			{
				SetDlgItemText(hwndDlg,IDC_UPDATEGAMES,buf);
				delete[] buf;
			}

			SetFocus(GetDlgItem(hwndDlg,IDOK));

			return TRUE;
		}
        case WM_COMMAND: 
            switch (LOWORD(wParam)) 
            { 
                case IDOK: 
					EndDialog(hwndDlg,IDOK);
                    return TRUE; 
 
                case IDCANCEL: 
					EndDialog(hwndDlg,IDCANCEL);
                    return TRUE; 
            } 
			break;
	}

	return FALSE;
}

void UpdateMyXFireIni(LPVOID dummy) {
	char request[1024];
	char file[1024];
	char file2[1024];
	char file3[1024];

	//ini pfad rausbekommen
	strcpy(file, XFireGetFoldersPath ("IniFile"));
	strcpy(file2,file);
	strcpy(file3,file);
	strcat(file,"xfire_games.new");
	strcat(file2,"xfire_games.ini");
	strcat(file3,"xfire_games.old");

	mir_snprintf(request,1024,"%s%d",INI_URLREQUEST,getfilesize(file2));

	if(CheckWWWContent(request))
	{
		if(db_get_b(NULL,protocolname,"dontaskforupdate",0)==1||DialogBox(hinstance,MAKEINTRESOURCE(IDD_UPDATE),NULL,DlgUpdateDialogProc)==IDOK)
		{
			if(GetWWWContent2(request,file,FALSE))
			{
				//altes backup löschen
				remove(file3);
				//derzeitige ini und sichern
				rename(file2,file3);
				//lösche .old, wenn aktiv
				if(db_get_b(NULL,protocolname,"nobackupini",0))
					remove(file3);
				//neue aktiv schalten
				rename(file,file2);
				
				if(db_get_b(NULL,protocolname,"dontaskforupdate",0)==0) MSGBOX(Translate("The xfire_games.ini was updated."));
			}
			else
				MSGBOX(Translate("Error during xfire_games Update."));
		}
	}
}

void UpdateMyIcons(LPVOID dummy) {
	char request[1024];
	char file[1024];
	char file2[1024];
	char file3[1024];

	//ini pfad rausbekommen
	strcpy(file,XFireGetFoldersPath ("IconsFile"));
	strcpy(file2,file);
	strcpy(file3,file);
	strcat(file,"icons.new");
	strcat(file2,"icons.dll");
	strcat(file3,"icons.old");

	mir_snprintf(request,1024,"%s%d",ICO_URLREQUEST,getfilesize(file2));

	if(CheckWWWContent(request))
	{
		if(db_get_b(NULL,protocolname,"dontaskforupdate",0)==1||MessageBox(NULL,Translate("There is a new Icons.dll online, do you want to update now?"),"Miranda XFire Protocol Plugin",MB_YESNO|MB_ICONQUESTION)==IDYES)
		{
			if(GetWWWContent2(request,file,FALSE)) {
				//altes backup löschen
				remove(file3);
				//derzeitige ini und sichern
				rename(file2,file3);
				//lösche .old, wenn aktiv
				if(db_get_b(NULL,protocolname,"nobackupini",0))
					remove(file3);
				//neue aktiv schalten
				rename(file,file2);
				
				if(db_get_b(NULL,protocolname,"dontaskforupdate",0)==0) MSGBOX(Translate("The Icons.dll was updated."));
			}
			else
				MSGBOX(Translate("Error during Icons.dll Update."));
		}
	}
}