Пример #1
0
 protected virtual void OnFileApply(FileApplyEventArgs e)
 {
     if (FileApplyEvent != null)
     {
         FileApplyEvent(this, e);
     }
 }
Пример #2
0
        void fileApply(object sender, FileApplyEventArgs e)
        {
            Debug.WriteLine("FileApply");
            string strApply = "";

            if (e.step == FileApplyEventArgs.STEP_COPY)
            {
                strApply = Msg.DEF_FILECOMMIT + " : " + e.applyMsg;
                sbLog.Append(strApply);
                setLbInfoText(strApply);
            }
            else
            {
                if (e.isError)
                {
                    sbLog.AppendLine(" - " + MsgERR.ERR_FAIL + " : \n" + e.applyMsg);
                }
                else
                {
                    sbLog.AppendLine(" - " + Msg.DEF_SUCCESS);
                }
            }
        }
Пример #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);
        }