private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { //file was selected and is ok so lets set the skin file variable to this file //---------load some properties ------------- try { // Create the file and clean up handles. //using (FileStream fs = File.Create(path)) { } // Ensure that the target does not exist. File.Delete(Application.StartupPath + "\\Skins\\new.skf"); // Copy the file. File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Skins\\new.skf"); //Console.WriteLine("{0} copied to {1}", path, path2); // Try to copy the same file again, which should succeed. //File.Copy(path, path2, true); //Console.WriteLine("The second Copy operation succeeded, which was expected."); settings.AppSkinPath = "\\Skins\\new.skf"; settings.Save(); #if !NO_SKINNABLE //SkinOb.LoadSkinFromFile(Application.StartupPath + "\\Skins\\Vista-style_ST.skf"); SkinOb.LoadSkinFromFile(Application.StartupPath + settings.AppSkinPath); SkinOb.ApplySkin(); #endif //MessageBox.Show("Skin change will take place once you restart rm2", Program.programName,MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (IOException IOe) { MessageBox.Show(IOe.ToString(), "Error loading the Skin File"); } }
/// <summary> /// /// </summary> /// <param name="webResponse">WebResponse</param> /// <param name="path">0 - 절대경로, 1 - 상대경로, 2 - 파일이름</param> public void receiveData(WebResponse webResponse, string[] path, ref DownProgressChangedEventHandler DownProgressChangedEvent, ref DownProgressCompletedEventHandler DownProgressCompletedEvent) { FileStream fileStream = null; string destZipDir = ""; try { string winTempDir = System.IO.Path.GetTempPath(); Debug.WriteLine("Window Temp Directory : " + winTempDir); //string destZipDir = path[0] + "\\" +path[1] + "\\"; destZipDir = winTempDir + "\\" + path[1] + "\\"; Directory.CreateDirectory(Path.GetDirectoryName(destZipDir)); byte[] fromBuff = new byte[256]; fileStream = new FileStream(destZipDir + "\\" + path[2], FileMode.OpenOrCreate, FileAccess.Write); int count = 0; double progressMaxValue = double.Parse(webResponse.ContentLength.ToString()); Stream readStream = webResponse.GetResponseStream(); // webResponse.GetResponseStream() /* * while ((read = bis.read(b)) != -1) { * outStream.write(b, 0, read); * } */ //while ((count = webResponse.GetResponseStream().Read(fromBuff, 0, fromBuff.Length)) > 0) while ((count = readStream.Read(fromBuff, 0, fromBuff.Length)) > 0) { //progressValue += fromBuff.Length; fileStream.Write(fromBuff, 0, count); //double bytesIn = double.Parse(progressValue.ToString()); double bytesIn = double.Parse(fileStream.Length.ToString()); //tempSize = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = (bytesIn / progressMaxValue) * 100; //ValidateEndEvent(this, e); DownProgressChangedEventArgs vEe = new DownProgressChangedEventArgs(int.Parse(Math.Truncate(percentage > 100 ? 100 : percentage).ToString()), bytesIn, progressMaxValue); if (DownProgressChangedEvent != null) { DownProgressChangedEvent(this, vEe); } //DownProgressChangedEvent(this,vEe); //.ValidateEndEvent();//.ValidateEnd(vEe); //bg.ReportProgress(int.Parse(Math.Truncate(percentage > 100 ? 100 : percentage).ToString()), bytesIn); } DownProgressCompletedEventArgs dCe = new DownProgressCompletedEventArgs(false, "");//(int.Parse(Math.Truncate(percentage > 100 ? 100 : percentage).ToString()), bytesIn); if (DownProgressCompletedEvent != null) { DownProgressCompletedEvent(this, dCe); } } catch (System.Threading.ThreadAbortException e) { Debug.WriteLine(e.ToString()); try { //DirectoryInfo dirInfo = new DirectoryInfo(targetPath + "\\" + pathDir); DirectoryInfo dirInfo = new DirectoryInfo(destZipDir); if (dirInfo.Exists) { FileInfo[] sfiles = dirInfo.GetFiles(); foreach (FileInfo fi in sfiles) { fi.Delete(); } dirInfo.Delete(); } } catch (Exception IOe) { Debug.WriteLine("an exception has occured in extracting : " + IOe.ToString()); } } finally { if (fileStream != null) { fileStream.Close(); } if (webResponse != null) { webResponse.Close(); } } }
private void extractZip(String targetPath, String pathDir, String zipFileName) { string strApplyMsg = ""; string strErrorMsg = Msg.DEF_SETFILECOMPLETE; string winTempDir = System.IO.Path.GetTempPath(); Boolean isSuccessful = true; try { string AbsoluteZipPath = winTempDir + "\\" + pathDir + "\\" + zipFileName; /// ------------ 적용 전 tmp파일 삭제 DirectoryInfo targetDi = new DirectoryInfo(targetPath); targetDi.GetFiles("*.tmp", SearchOption.AllDirectories).ToList().ForEach( delegate(FileInfo file) { System.Text.RegularExpressions.Regex cntStr = new System.Text.RegularExpressions.Regex("."); int cntDot = cntStr.Matches(file.FullName, 0).Count; if (cntDot > 1) { file.Delete(); } }); using (ZipFile zip1 = ZipFile.Read(AbsoluteZipPath)) { foreach (ZipEntry e in zip1) { try { FileApplyEventArgs fAe = new FileApplyEventArgs(false, e.FileName, FileApplyEventArgs.STEP_COPY); OnFileApply(fAe); String[] strUpdate = { "PatchForm.exe", "PatchManager.dll", "Newtonsoft.Json.dll", "Ionic.Zip.dll" }; try { if (strUpdate.Contains(e.FileName)) { Debug.WriteLine("file move : " + e.FileName); targetDi.GetFiles(e.FileName).ToList().ForEach(file => file.MoveTo(targetPath + "\\" + e.FileName + ".oldFile")); } else { Debug.WriteLine("file delete : " + e.FileName); targetDi.GetFiles(e.FileName).ToList().ForEach(file => file.Delete()); } } catch (System.IO.DirectoryNotFoundException de) { Debug.WriteLine("Error has occured during post-delete targetfile : " + de); } catch (Exception fe) { Debug.WriteLine("Error has occured during post-delete targetfile : " + fe); } e.Extract(targetPath, ExtractExistingFileAction.OverwriteSilently); fAe = new FileApplyEventArgs(false, "", FileApplyEventArgs.STEP_END); OnFileApply(fAe); } catch (Exception zipE) { isFileError = true; FileApplyEventArgs fAe = new FileApplyEventArgs(true, zipE.ToString(), FileApplyEventArgs.STEP_END); OnFileApply(fAe); } } } } catch (Exception e) { Debug.WriteLine("an exception has occured : " + e.ToString()); strApplyMsg = e.GetType().ToString() + "\n"; strErrorMsg = e.ToString(); isSuccessful = false; } finally { try { DirectoryInfo dirInfo = new DirectoryInfo(winTempDir + "\\" + pathDir); if (dirInfo.Exists) { FileInfo[] sfiles = dirInfo.GetFiles(); foreach (FileInfo fi in sfiles) { fi.Delete(); } dirInfo.Delete(); } } catch (Exception IOe) { Debug.WriteLine("an exception has occured in extracting : " + IOe.ToString()); isSuccessful = false; strErrorMsg = IOe.ToString(); } } FileApplyCompletedEventArgs fAce = new FileApplyCompletedEventArgs(!isSuccessful, strErrorMsg); OnFileApplyCompleted(fAce); }