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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| private List<Version> GetVersions()
{
var dico = new List<Version>();
myWebClient.DownloadFile(Settings.Configuration.LinkDownload + "versions.txt", "./UpLauncher/versions.txt");
var LauncherReader = new System.IO.StreamReader("./UpLauncher/versions.txt", Encoding.Default);
while (!LauncherReader.EndOfStream)
{
var line = LauncherReader.ReadLine();
if (line.Contains(">"))
dico.Add(new Version()
{
ID = int.Parse(line.Split('>')[0].Trim()),
ActualVersion = line.Split('>')[1].Trim(),
Description = line.Split('>')[2].Trim(),
});
}
LauncherReader.Close();
System.IO.File.Delete("./UpLauncher/versions.txt");
return dico;
}
private void Initialize()
{
if (System.IO.File.Exists("./UpLauncher/configuration.conf"))
{
var reader = new StreamReader("./UpLauncher/configuration.conf", Encoding.Default);
Settings.Configuration.LinkDofus = reader.ReadLine().Split('=')[1];
myVersion.ActualVersion = reader.ReadLine().Split('=')[1];
reader.Close();
}
else
{
AddToLog("Fichier de configuration inexistant ou corrompu, remise à zéro.", true, true);
var writer = new StreamWriter("./UpLauncher/configuration.conf", false, Encoding.Default);
writer.AutoFlush = true;
writer.WriteLine(@"LinkDofus=.\Dofus.exe");
writer.WriteLine(@"VersionDofus=1.0.0");
writer.WriteLine(@"LinkDownload=http://127.0.0.1/download/");
writer.Close();
Settings.Configuration.LinkDofus = @".\Dofus.exe";
Settings.Configuration.LinkDownload = @"http://127.0.0.1/download/";
myVersion.ActualVersion = "1.0.0";
}
AddToLog("Version de l'UpLauncher : " + Settings.Configuration.LauncherVersion + " !", true);
AddToLog("Version de l'application DOFUS : " + myVersion.ActualVersion + " !", true);
}
private bool VerifVersion(ref string game)
{
if (!System.IO.Directory.Exists("./UpLauncher"))
System.IO.Directory.CreateDirectory("./UpLauncher");
var LauncherVersion = myWebClient.DownloadString(Settings.Configuration.LinkDownload + "launcher.txt");
if (LauncherVersion != Settings.Configuration.LauncherVersion)
{
var result = MessageBox.Show("Une nouvelle version de l'UpLauncher est disponible, nous allons vous rediriger sur le site pour que vous puissez vous mettre à jour vers la version '" + LauncherVersion + "' !", "Nouvelle version disponible !", MessageBoxButton.OK);
if (result == MessageBoxResult.OK)
System.Diagnostics.Process.Start(Settings.Configuration.LinkSite);
Environment.Exit(0);
}
game = myWebClient.DownloadString(Settings.Configuration.LinkDownload + "client.txt");
AddToLog("Dernière version détectée : " + game + " !", true);
return new Version() { ActualVersion = game }.IsBigger(myVersion);
}
private void StartUpdate(Version VersionToDownload)
{
this.progress.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
progress.IsIndeterminate = false;
progress.Value = 0;
}));
AddToLog("Téléchargement de la version [" + VersionToDownload.ActualVersion + "] (" + VersionToDownload.Description + ") ...", false);
myWebClient.DownloadFileAsync(new Uri(Settings.Configuration.LinkDownload + "updates/" + VersionToDownload.ActualVersion + ".zip"), "./UpLauncher/" + VersionToDownload.ActualVersion + ".zip");
myWebClient.DownloadProgressChanged += (s, e) =>
{
this.progress.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
progress.Value = e.ProgressPercentage;
}));
};
myWebClient.DownloadFileCompleted += (s, e) =>
{
StartUnpressUpdate(VersionToDownload);
};
}
private void ChangeProgressEnabled(bool ena)
{
this.progress.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
if (ena == true)
progress.Visibility = System.Windows.Visibility.Visible;
else
progress.Visibility = System.Windows.Visibility.Hidden;
}));
}
private void StartUnpressUpdate(Version VersionToDownload)
{
this.progress.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
progress.IsIndeterminate = true;
progress.Value = 0;
}));
AddToLog("Décompression de la version [" + VersionToDownload.ActualVersion + "] (" + VersionToDownload.Description + ") ...", false);
try
{
ZipInputStream zis = null;
FileStream fos = null;
zis = new ZipInputStream(new FileStream("./UpLauncher/" + VersionToDownload.ActualVersion + ".zip", FileMode.Open, FileAccess.Read));
ZipEntry ze;
while ((ze = zis.GetNextEntry()) != null)
{
if (ze.IsDirectory)
Directory.CreateDirectory(@".\Game\\" + ze.Name);
else
{
if (!Directory.Exists(@".\Game\\" + System.IO.Path.GetDirectoryName(ze.Name)))
Directory.CreateDirectory(@".\Game\\" + System.IO.Path.GetDirectoryName(ze.Name));
fos = new FileStream(@".\Game\\" + ze.Name, FileMode.Create, FileAccess.Write);
int count;
byte[] buffer = new byte[4096];
while ((count = zis.Read(buffer, 0, 4096)) > 0)
fos.Write(buffer, 0, count);
}
}
if (zis != null)
zis.Close();
if (fos != null)
fos.Close();
if (File.Exists("./UpLauncher/" + VersionToDownload.ActualVersion + ".zip"))
System.IO.File.Delete("./UpLauncher/" + VersionToDownload.ActualVersion + ".zip");
}
catch
{
AddToLog("Erreur lors de la décompression !", true, true);
return;
}
AddToLog("Mise à jour [" + VersionToDownload.ActualVersion + "] (" + VersionToDownload.Description + ") installée !", true);
myVersion.ActualVersion = VersionToDownload.ActualVersion;
Settings.Configuration.SaveConf(myVersion.ActualVersion);
if (VerifVersion(ref gameVersion))
{
AddToLog("Version à jour !", true, true);
ChangePlayEnabled(true);
ChangeProgressEnabled(false);
myWebClient.Dispose();
foreach (var file in Directory.GetFiles("./UpLauncher/"))
{
if (file.Split('/')[file.Split('/').Length - 1] == "configuration.conf")
continue;
File.Delete(file);
}
}
else
{
Versions.Remove(VersionToDownload);
myWebClient = new WebClient();
myWebClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
myWebClient.Headers.Add("Cache-Control", "no-cache");
StartUpdate(Versions.Where(x => !x.IsBigger(myVersion)).OrderBy(x => x.ID).ToArray()[0]);
}
} |
Partager