-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallUpdate.ClientDataFile.cs
More file actions
183 lines (140 loc) · 6.84 KB
/
Copy pathInstallUpdate.ClientDataFile.cs
File metadata and controls
183 lines (140 loc) · 6.84 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using wyUpdate.Common;
namespace wyUpdate
{
partial class InstallUpdate
{
public void RunUpdateClientDataFile()
{
bw.DoWork += bw_DoWorkClientData;
bw.ProgressChanged += bw_ProgressChanged;
bw.RunWorkerCompleted += bw_RunWorkerCompletedClientData;
bw.RunWorkerAsync();
}
void bw_DoWorkClientData(object sender, DoWorkEventArgs e)
{
Exception except = null;
try
{
OutputDirectory = Path.Combine(TempDirectory, "ClientData");
Directory.CreateDirectory(OutputDirectory);
string oldClientFile = null;
// see if a 1.1+ client file exists (client.wyc)
if (ClientFileType != ClientFileType.Final
&& File.Exists(Path.Combine(Path.GetDirectoryName(Filename), "client.wyc")))
{
oldClientFile = Filename;
Filename = Path.Combine(Path.GetDirectoryName(Filename), "client.wyc");
ClientFileType = ClientFileType.Final;
}
if (ClientFileType == ClientFileType.PreRC2)
{
//convert pre-RC2 client file by saving images to disk
string tempImageFilename;
//create the top image
if (ClientFile.TopImage != null)
{
ClientFile.TopImageFilename = "t.png";
tempImageFilename = Path.Combine(OutputDirectory, "t.png");
ClientFile.TopImage.Save(tempImageFilename, System.Drawing.Imaging.ImageFormat.Png);
}
//create the side image
if (ClientFile.SideImage != null)
{
ClientFile.SideImageFilename = "s.png";
tempImageFilename = Path.Combine(OutputDirectory, "s.png");
ClientFile.SideImage.Save(tempImageFilename, System.Drawing.Imaging.ImageFormat.Png);
}
}
else
{
//Extract the contents of the client data file
ExtractUpdateFile();
if (File.Exists(Path.Combine(OutputDirectory, "iuclient.iuc")))
{
// load and merge the existing file
ClientFile tempClientFile = new ClientFile();
tempClientFile.LoadClientData(Path.Combine(OutputDirectory, "iuclient.iuc"));
tempClientFile.InstalledVersion = ClientFile.InstalledVersion;
ClientFile = tempClientFile;
File.Delete(Path.Combine(OutputDirectory, "iuclient.iuc"));
}
}
List<UpdateFile> updateDetailsFiles = UpdtDetails.UpdateFiles;
FixUpdateFilesPaths(updateDetailsFiles);
//write the uninstall file
RollbackUpdate.WriteUninstallFile(TempDirectory, Path.Combine(OutputDirectory, "uninstall.dat"), updateDetailsFiles);
List<UpdateFile> files = new List<UpdateFile>();
//add all the files in the outputDirectory
AddFiles(OutputDirectory.Length + 1, OutputDirectory, files);
//recompress all the client data files
string tempClient = Path.Combine(TempDirectory, "client.file");
ClientFile.SaveClientFile(files, tempClient);
// overrite existing client.wyc, while keeping the file attributes
FileAttributes atr = FileAttributes.Normal;
if (File.Exists(Filename))
atr = File.GetAttributes(Filename);
bool resetAttributes = (atr & FileAttributes.Hidden) != 0 || (atr & FileAttributes.ReadOnly) != 0 || (atr & FileAttributes.System) != 0;
// remove the ReadOnly & Hidden atributes temporarily
if (resetAttributes)
File.SetAttributes(Filename, FileAttributes.Normal);
//replace the original
File.Copy(tempClient, Filename, true);
if (resetAttributes)
File.SetAttributes(Filename, atr);
if (oldClientFile != null)
{
// delete the old client file
File.Delete(oldClientFile);
}
}
catch (Exception ex)
{
// handle failed to write to client file
except = ex;
}
if (except != null)
{
// tell the main window we're rolling back registry
bw.ReportProgress(1, true);
// rollback started services
RollbackUpdate.RollbackStartedServices(TempDirectory);
// rollback newly regged COM dlls
RollbackUpdate.RollbackRegedCOM(TempDirectory);
// rollback the registry
RollbackUpdate.RollbackRegistry(TempDirectory);
//rollback files
bw.ReportProgress(1, false);
RollbackUpdate.RollbackFiles(TempDirectory, ProgramDirectory);
// rollback unregged COM
RollbackUpdate.RollbackUnregedCOM(TempDirectory);
// rollback stopped services
RollbackUpdate.RollbackStoppedServices(TempDirectory);
bw.ReportProgress(0, new object[] { -1, -1, string.Empty, ProgressStatus.Failure, except });
}
else
{
bw.ReportProgress(0, new object[] { -1, -1, string.Empty, ProgressStatus.Success, null });
}
}
void bw_RunWorkerCompletedClientData(object sender, RunWorkerCompletedEventArgs e)
{
bw.DoWork -= bw_DoWorkClientData;
bw.ProgressChanged -= bw_ProgressChanged;
bw.RunWorkerCompleted -= bw_RunWorkerCompletedClientData;
}
//creates list of files to add to client data file
static void AddFiles(int charsToTrim, string dir, List<UpdateFile> files)
{
string[] filenames = Directory.GetFiles(dir);
string[] dirs = Directory.GetDirectories(dir);
foreach (string file in filenames)
files.Add(new UpdateFile { Filename = file, RelativePath = file.Substring(charsToTrim) });
foreach (string directory in dirs)
AddFiles(charsToTrim, directory, files);
}
}
}