private void TestUpload(string skinname) { // Given a selected file, download this and all included/imported files string mainleaf; mainleaf = "HTMLOutput.xsl"; object sender = System.Threading.Thread.CurrentThread; string rootfile = this.PathToSkins.Text + @"\" + mainleaf; string rootdir = this.PathToSkins.Text; string tempfilesroot = Application.UserAppDataPath + @"\skins"; string subfilesroot = tempfilesroot + @"\" + skinname; string mainskinpath = tempfilesroot + @"\" + skinname + @"\" + mainleaf; RichBoxArgs a = new RichBoxArgs("Testing " + rootfile + "\r\n", true); this.WriteToRichBox(sender, a); a.clear = false; a.stringToWrite = "dowloading files\r\n"; this.WriteToRichBox(sender, a); DownloadSkinFile(tempfilesroot, subfilesroot, mainleaf, skinname, new SortedList(), false, "default"); /* * Now we've got the skins from live, apply the changes (one by one) and see if it still works * We can rearrange the filenames in the list in order to accomodate the success or otherwise * * Simply put: Go down the list of selected items until one fails, then keep going until one * succeeds, then swap the failure and success, then start again from the next * one. If you run out of files and they've all failed, report the problem * */ int current = 0; int lastfailed = 0; int iFilecount = this.GetCheckedFileCount(); while (current < iFilecount && lastfailed < iFilecount) { // rename existing file in the test directory string curfilename = subfilesroot + @"\" + this.GetCheckedFilename(current); string filetocopy = rootdir + @"\" + this.GetCheckedFilename(current); string renamefile = subfilesroot + @"\" + this.GetCheckedFilename(current) + ".___temp"; a.stringToWrite = "Trying " + this.GetCheckedFilename(current) + "..."; this.WriteToRichBox(sender, a); bool bFileExists = System.IO.File.Exists(curfilename); if (bFileExists) { System.IO.Directory.Move(curfilename, renamefile); } System.IO.File.Copy(filetocopy, curfilename, true); string result; if (TestXSLTFile(mainskinpath, out result)) { a.stringToWrite = "succeeded\r\n"; this.WriteToRichBox(sender, a); // succeeded if (bFileExists) { System.IO.File.Delete(renamefile); } if (current != lastfailed) { a.stringToWrite = "Swapping " + this.GetCheckedFilename(current) + " with " + this.GetCheckedFilename(lastfailed); this.WriteToRichBox(sender, a); SwapFileItemsArgs arg = new SwapFileItemsArgs(current, lastfailed); SwapFileItems(sender, arg); lastfailed = current; } else { current++; lastfailed = current; } } else { a.stringToWrite = "failed (" + result + ")\r\n"; this.WriteToRichBox(sender, a); System.IO.File.Delete(curfilename); if (bFileExists) { System.IO.File.Move(renamefile, curfilename); } current++; } } if (current == lastfailed) { a.stringToWrite = "All files successfully tested\r\n"; this.WriteToRichBox(sender, a); } else { a.stringToWrite = this.directoryStructure.Nodes[lastfailed].Text + " cannot be uploaded\r\n"; this.WriteToRichBox(sender, a); } }
void SwapFileItems(object sender, SwapFileItemsArgs a) { if (this.InvokeRequired == false) { TreeNode temp = this.directoryStructure.Nodes[a.firstindex]; this.directoryStructure.Nodes[a.firstindex] = this.directoryStructure.Nodes[a.firstindex]; this.directoryStructure.Nodes[a.firstindex] = temp; } else { SwapFileItemsHandler handler = new SwapFileItemsHandler(SwapFileItems); Invoke(handler, new object[] { sender, a }); } }