Exemple #1
0
 protected virtual void OnFileApplyCompleted(FileApplyCompletedEventArgs e)
 {
     if (FileApplyCompletedEvent != null)
     {
         FileApplyCompletedEvent(this, e);
     }
 }
Exemple #2
0
        void endFileApply(object sender, FileApplyCompletedEventArgs e)
        {
            sbLog.AppendLine(System.DateTime.Today.ToString() + " - " + e.errorMsg);

            /*
             * Debug.WriteLine("FileApplyCompleted");
             * string result = "";
             * if (!e.isError)
             * {
             *  result = "업데이트가 성공적으로 완료되었습니다.";
             * }
             * else
             * {
             *  if (e.errorMsg.Trim().Equals(""))
             *      result = "실행 중 문제가 발생하였습니다.\n프로그램을 다시 실행해 주세요.";
             *  else
             *      result = "다음과 같은 에러가 발생하였습니다 : \n" + e.errorMsg;
             * }
             * setLbInfoText("업데이트 완료");
             * sbLog.AppendLine(result);
             * MessageBox.Show(result);//.Temp.ToString());
             * Application.Exit();*/
        }
Exemple #3
0
        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);
        }