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(); } } }
// Метод PrintMenu отвечает за отображение файлов и директорий и за действие с ними. public void PrintMenu() { bool isRunning = true; var leftPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); string rightPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); string path = leftPath; int leftIndex = 0; int rightIndex = 0; int index = 0; int position = 0; int page = 1; Side side = Side.Left; string sourceFileName = null, destFileName = null; PrintElements(GetElements(leftPath), Side.Left, leftPath, index, page); PrintElements(GetElements(rightPath), Side.Right, rightPath, index, page); while (isRunning) { object[] elements = GetElements(path); if (elements.Length > 0) { PrintInfo(elements[index], position, side, ConsoleColor.Red); } ConsoleKeyInfo keyInfo = Console.ReadKey(); switch (keyInfo.Key) { case ConsoleKey.DownArrow: if (elements.Length > 0) { PrintInfo(elements[index], position, side, ConsoleColor.Gray); } index = index + 1 > elements.Length - 1 ? 0 : index + 1; position = index % 22; if (position == 0) { page = 1 + index / 22; ClearSide(side); PrintElements(elements, side, path, index, page); } break; case ConsoleKey.UpArrow: if (elements.Length > 0) { PrintInfo(elements[index], position, side, ConsoleColor.Gray); } index = index - 1 < 0 ? elements.Length - 1 : index - 1; position = index % 22; if (position == 21 || index == elements.Length - 1) { page = 1 + index / 22; ClearSide(side); PrintElements(elements, side, path, index - position, page); } break; case ConsoleKey.LeftArrow: if (side != Side.Left) { if (elements.Length > 0 && side != Side.Left) { PrintInfo(elements[index], position, side, ConsoleColor.Yellow); } rightIndex = index; path = leftPath; side = Side.Left; index = leftIndex; position = index % 22; } break; case ConsoleKey.RightArrow: if (side != Side.Right) { if (elements.Length > 0) { PrintInfo(elements[index], position, side, ConsoleColor.Yellow); } leftIndex = index; path = rightPath; side = Side.Right; index = rightIndex; position = index % 22; } break; case ConsoleKey.Backspace: if (side == Side.Left) { if (leftPath != null && new DirectoryInfo(leftPath).Parent != null) { leftPath = new DirectoryInfo(leftPath).Parent.FullName.ToString(); path = leftPath; } else { leftPath = null; path = null; } } else { if (rightPath != null && new DirectoryInfo(rightPath).Parent != null) { rightPath = new DirectoryInfo(rightPath).Parent.FullName.ToString(); path = rightPath; } else { rightPath = null; path = null; } } if (elements.Length > 0) { PrintInfo(elements[index], position, side, ConsoleColor.Gray); } ClearSide(side); index = 0; position = 0; page = 1; PrintElements(GetElements(path), side, path, index, page); break; case ConsoleKey.Enter: if (elements[index].GetType() == typeof(DirectoryInfo)) { DirectoryInfo directoryInfo = (DirectoryInfo)elements[index]; if (side == Side.Left) { leftPath = directoryInfo.FullName; path = leftPath; } else { rightPath = directoryInfo.FullName; path = rightPath; } PrintInfo(elements[index], position, side, ConsoleColor.Gray); index = 0; position = 0; page = 1; ClearSide(side); PrintElements(GetElements(path), side, path, index, page); } else if (elements[index].GetType() == typeof(DriveInfo)) { DriveInfo driveInfo = (DriveInfo)elements[index]; if (side == Side.Left) { leftPath = driveInfo.Name; path = leftPath; } else { rightPath = driveInfo.Name; path = rightPath; } PrintInfo(elements[index], position, side, ConsoleColor.Gray); index = 0; position = 0; page = 1; ClearSide(side); PrintElements(GetElements(path), side, path, index, page); } else { string pathToFile = Path.Combine(path, GetName(elements[index])); System.Diagnostics.Process.Start(pathToFile); } break; case ConsoleKey.B: if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) { if (elements.Length > 0 && elements[index].GetType() != typeof(DriveInfo) && sourceFileName != null) { FileInfo info = new FileInfo(sourceFileName); string fileName = info.Name; string type = info.Extension; try { destFileName = Path.Combine(path, fileName); File.Copy(sourceFileName, destFileName); } catch (IOException IOe) { IOe.GetBaseException(); FileInfo[] infos = new DirectoryInfo(path).GetFiles(); List <string> listInfos = new List <string>(); foreach (FileInfo f in infos) { if (!f.Attributes.HasFlag(FileAttributes.Hidden)) { listInfos.Add(f.Name); } } fileName = AddCountToFileName(fileName, type); while (listInfos.Contains(fileName)) { fileName = AddCountToFileName(fileName, type); } destFileName = Path.Combine(path, fileName); File.Copy(sourceFileName, destFileName); } if (leftPath.Equals(rightPath)) { ClearSide(Side.Left); ClearSide(Side.Right); index = 0; position = 0; page = 1; PrintElements(GetElements(leftPath), Side.Left, leftPath, index, page); PrintElements(GetElements(rightPath), Side.Right, rightPath, index, page); } else { ClearSide(side); index = 0; position = 0; page = 1; PrintElements(GetElements(path), side, path, index, page); } break; } } break; case ConsoleKey.X: if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) { if (elements.Length > 0 && elements[index].GetType() != typeof(DriveInfo) && elements[index].GetType() != typeof(DirectoryInfo)) { sourceFileName = Path.Combine(path, GetName(elements[index])); PrintInfo(elements[index], position, side, ConsoleColor.Green); Thread.Sleep(1000); } } break; case ConsoleKey.Delete: if (elements.Length > 0 && elements[index].GetType() != typeof(DirectoryInfo) && elements[index].GetType() != typeof(DriveInfo)) { if (leftPath.Equals(rightPath)) { File.Delete(Path.Combine(path, GetName(elements[index]))); ClearSide(Side.Left); ClearSide(Side.Right); index = index - 1 < 0 ? 0 : index - 1; position = index % 22; page = 1 + index / 22; elements = GetElements(path); PrintElements(elements, Side.Left, leftPath, index - position, page); PrintElements(elements, Side.Right, rightPath, index - position, page); } else { File.Delete(Path.Combine(path, GetName(elements[index]))); ClearSide(side); index = index - 1 < 0 ? 0 : index - 1; position = index % 22; page = 1 + index / 22; elements = GetElements(path); PrintElements(elements, side, path, index - position, page); } } break; case ConsoleKey.Insert: if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) { if (elements.Length == 0 || elements[index].GetType() != typeof(DriveInfo)) { Console.Clear(); string fileName = GetNameFromEditName(); Console.Clear(); //PrintContainersForManager(); if (fileName.Length > 0) { string fullPath = Path.Combine(path, fileName); FileStream fileStream = new FileStream(fullPath, FileMode.Create); fileStream.Close(); if (leftPath.Equals(rightPath)) { leftIndex++; rightIndex++; PrintElements(GetElements(leftPath), Side.Left, leftPath, leftIndex - leftIndex % 22, 1 + leftIndex / 22); PrintElements(GetElements(rightPath), Side.Right, rightPath, rightIndex - rightIndex % 22, 1 + rightIndex / 22); } else { index = index + 1 == 1 ? 0 : index + 1; position = index % 22; page = 1 + index / 22; elements = GetElements(path); PrintElements(elements, side, path, index - position, page); if (side == Side.Left) { PrintElements(GetElements(rightPath), Side.Right, rightPath, rightIndex - rightIndex % 22, 1 + rightIndex / 22); } else { PrintElements(GetElements(leftPath), Side.Left, leftPath, leftIndex - leftIndex % 22, 1 + leftIndex / 22); } } } else { PrintElements(GetElements(leftPath), Side.Left, leftPath, leftIndex, 1); PrintElements(GetElements(rightPath), Side.Right, rightPath, rightIndex, 1); } } } break; } } }
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); }