Всем добрый вечер. Были у меня исходники одного updatera для Aion (mmorpg)
Переделал их немножко и т.д
И столкнулся с проблемой.
Само обновление происходит там таким методом.
Прошу прощения спойлера не нашел.
C# |
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;
using System.Net.Sockets;
namespace Aion_Launcher
{
class Updater
{
string launchPath = Application.StartupPath;
string[] lines;
List<ClientFile> clientFiles = new List<ClientFile>();
public UpdaterTemp temp;
public void selfUpdate()
{
if (!Settings.launchUpdateEnabled)
return;
try
{
WebClient client = new WebClient();
string actual = client.DownloadString(Settings.launchFilesUrl + "/version.txt");
string current = Application.ProductVersion;
if (!File.Exists("update.exe"))
{
Uri ui = new Uri(Settings.launchFilesUrl + "/update.exe");
WebClient c = new WebClient();
c.DownloadFile(ui, launchPath + "\\update.exe");
}
if (!actual.Equals(current))
{
Process.Start("update.exe");
Environment.Exit(0);
}
}
catch { }
}
public void downloadHashes()
{
try
{
WebClient webClient = new WebClient();
Uri ui = new Uri(Settings.clientUrl + "/hash.txt");
webClient.DownloadFile(ui, launchPath + "\\hash.txt");
lines = File.ReadAllLines(Application.StartupPath + "\\hash.txt");
File.Delete(Application.StartupPath + "\\hash.txt");
}
catch
{
System.Windows.Forms.MessageBox.Show("Не удалось подключиться к серверу обновления.", "Внимание!");
}
}
public void update()
{
downloadHashes();
if (lines == null)
{
temp.button_play.Enabled = true;
temp.button_update.Enabled = true;
return;
}
foreach (String line in lines)
{
string[] fileInfo = line.Split(':');
clientFiles.Add(new ClientFile(fileInfo[0], fileInfo[1]));
}
checkFolders(clientFiles);
foreach (ClientFile clientFile in clientFiles)
{
string path = (launchPath + "\\" + clientFile.Name);
bool exists = System.IO.File.Exists(path);
if (!exists || isUpdateRequired(path, clientFile.Hash))
{
temp.filesToUpdate++;
temp.filesRemains++;
}
}
foreach (ClientFile clientFile in clientFiles)
{
string path = (launchPath + "\\" + clientFile.Name);
bool exists = System.IO.File.Exists(path);
if (!exists || isUpdateRequired(path, clientFile.Hash))
{
downloadFile(clientFile.Name);
}
}
temp.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
if (temp.filesRemains == 0)
temp.onUpdateEnd();
}
public void checkFolders(List<ClientFile> list)
{
foreach (ClientFile clientFile in list)
{
string filePath = (Application.StartupPath + "\\" + clientFile.Name);
string[] patterns = filePath.Split('\\');
int num = patterns.Length;
if (num > 0)
{
string path = Program.delLastpattern(filePath, '\\');
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
}
}
public void downloadFile(string fileName)
{
try
{
WebClient web = new WebClient();
Uri url = new Uri(Settings.clientUrl + fileName);
web.DownloadFileCompleted += new AsyncCompletedEventHandler(temp.client_DownloadFileCompleted);
web.DownloadFileAsync(url, launchPath + "\\" + fileName);
}
catch { }
}
public bool isUpdateRequired(string path, string hashcode)
{
FileInfo file = new FileInfo(path);
string hash = Program.GetHashString(file.Length.ToString());
if (!hash.Equals(hashcode))
return true;
else
return false;
}
}
class UpdaterTemp
{
public int filesToUpdate = 0;
public int filesRemains = 0;
public ProgressBar progressBar;
public Label label;
public Button button_play;
public Button button_update;
public UpdaterTemp(ProgressBar pb, Label label, Button button_play, Button button_update)
{
this.progressBar = pb;
this.label = label;
this.button_play = button_play;
this.button_update = button_update;
}
public void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
filesRemains--;
label.Text = "Осталось файлов: " + filesRemains;
if (filesRemains == 0)
{
onUpdateEnd();
}
}
public void onUpdateEnd()//Надо править для другого дийзайна начну с 26.03.12
{
button_play.Enabled = true;
button_update.Enabled = true;
label.Text = "Обновление завершено!";
progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
progressBar.Value = 100;
}
}
} |
|
Так вот. А настройки он сюда вызывает из файла настроек содержимае которого таково.
C# |
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
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//
//Основной конфиг апдейтера
//
namespace Aion_Launcher
{
class Settings
{
public static int gameseverPort = 7777;
public static int loginserverPort = 2106;
public static bool onlineEnabled = false;
public static bool newsEnabled = false;
public static bool launchUpdateEnabled = false;
public static bool deleteFilesEnabled = false;// Опасная функция...Если не найдет bin32 то удалит все файлы в своей директории
public static string[] allowedFiles = { "Aion Launcher.exe", "update.exe", "cc.ini", "Pub.key", "system.cfg" };
public static string clientUrl = "http://test.ru/updater/";
public static string launchFilesUrl = "http://test.ru/updater/";
public static string onlineUrl = "http://x.x.x.x/test/online.txt";
public static string gameseverIP = "127.0.0.1";
public static string loginserverIP = "127.0.0.1";
}
} |
|
Как можно увидеть из настроек .Я настроил это дело на danver для прверки. Создал папачку /updater/
А в нее поместил version.txt как сказано тут:
C# |
1
| string actual = client.DownloadString(Settings.launchFilesUrl + "/version.txt"); |
|
И запускаю программу , а она не запускается но иногда вылазит какойто bios updater??
Не запускается когда параметр устанавливаю на True
C# |
1
| public static bool launchUpdateEnabled = false; |
|
а иногда нет.
собственно что должно находится в файле version.txt
Точнее формат.Да и как убрать этот bios Updater
И просто скачивать файлы если в version.txt цифра больше чем у меня
Собственно что вам понятно из этого кода?)
Добавлено через 27 минут
если потребуется скину исходники других файлов этого проекта.