What WyUpdate Does

Hi,

I am trying to write my own update for my application data (as I find WyUpdate to be to diverse/sophisticated).

I would like to know how exactly the copying of the files is completed. In C# when I use System.IO.File.WriteAllBytes my application freezes, or fails to execute. WyUpdate had no problem, however. I just dropped files I need to update into the Updates tab and I was good to go for each update.

So here is what I am doing.

When I manually copy and paste a file from one directory to another, and run my application, it runs just fine. However, for some reason, when I use `System.IO.File.WriteAllBytes` to overwrite a file it causes my application to freeze.

What is the way to mimic manually copying and pasting a file from one directory to another? To ensure that my application does not freeze.

The problems are again:

1) Windows form application uses File.WriteAllBytes on the Applications _Data file. 2) Unity Standalone .EXE file will not run or will freeze

When it does NOT run, I get the error: "Failed to initialize player" details: "Could not preload global game manager #0.

When it does run it will freeze over the code of the files that have been updated.

Can someone please tell me why Unity does like files been updated in this way?

On my local machine, if I simply copy files from a version 1.2 to a version 1.1 file, the application.exe runs just fine

This is the code that I have written with the `System.IO.File.WriteAllBytes` in my form:

private void PrepareToDownload () { string startupPath = Application.StartupPath; /* * This finds the files within the users installation folder */ string[] files = Directory.GetFiles(startupPath + "\\App_Data", "*.*", SearchOption.AllDirectories);

using (WebClient webClient = new WebClient()) { foreach (string s in files) { /* * This gets the folder and subfolders after the main directory */ string filePath = s.Substring(s.IndexOf("App_Data")); downloadFile(webClient, "<user>:<pass>@mysite.tk/updates/" + filePath, startupPath + "\\" + filePath, File.ReadAllBytes(s)); } }

public void downloadFile (WebClient webClient, string urlAddress, string location, byte[] localFile) { webClient.Proxy = null; webClient.Credentials = new NetworkCredential("<user>", "<pass>"); byte[] fileData = webClient.DownloadData("ftp://"+ urlAddress); /* * Only download if bytes of remote file * is larger than bytes of local file */ if (fileData.Length > localFile.Length) { File.WriteAllBytes(location, fileData); } }

The question: How can I safely overwrite a file so that my application does not freeze when it runs?

My Application does not freeze when I manually copy and paste the updated files from the old directory to the new directory - is there a way to programmatically mimic that behavior?

When clicking the 'red x' button at the top right-hand corner of the application window, I receive a safe exit.

I am trying to write my own update for my application data (as I find WyUpdate to be to diverse/sophisticated).

wyUpdate is diverse and sophisticated because it needs to be. Updating is not as simple as DownloadFile(), File.Copy(). If it were then everyone would just write those couple lines of code to their app to add updating.

Read the source code to see how wyUpdate works.

Thanks Sam,

Please let me congratulate Wyatt and his team of well educated developers!

I am writing my own update because I am looking to achieve single purpose behavior. Is the WyUpdate team at liberty to discuss how the files are copied?

For some reason, the System.IO.File.WriteAllBytes function is not "safe" - what I mean by that is that my application will 'freeze' when the code runs over the files that were overwritten.

WyUpdate, however, has 'zero-problem' with copying my files.

I am just looking to achieve single purpose, of updating my files. If I were to peek at the functionality that makes up this behavior, where might I look?

JosephComputer Science Student