예제 #1
0
        public static void CopyDirectory(string src, string dst)
        {
            String[] files;

            if (dst[dst.Length - 1] != Path.DirectorySeparatorChar)
            {
                dst += Path.DirectorySeparatorChar;
            }
            if (!SafeDirectory.Exists(dst))
            {
                SafeDirectory.CreateDirectory(dst);
            }
            files = SafeDirectory.GetFileSystemEntries(src);
            foreach (string element in files)
            {
                // Sub directories

                if (SafeDirectory.Exists(element))
                {
                    CopyDirectory(element, dst + Path.GetFileName(element));
                }
                // Files in directory

                else
                {
                    SafeFile.Copy(element, dst + Path.GetFileName(element), true);
                }
            }
        }
예제 #2
0
        public static void CopyDirectory(string Src, string Dst)
        {
            String[] Files;

            if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
            {
                Dst += Path.DirectorySeparatorChar;
            }
            if (!SafeDirectory.Exists(Dst))
            {
                SafeDirectory.CreateDirectory(Dst);
            }
            Files = SafeDirectory.GetFileSystemEntries(Src);
            foreach (string Element in Files)
            {
                // Sub directories

                if (SafeDirectory.Exists(Element))
                {
                    CopyDirectory(Element, Dst + Path.GetFileName(Element));
                }
                // Files in directory

                else
                {
                    SafeFile.Copy(Element, Dst + Path.GetFileName(Element), true);
                }
            }
        }
 public static void RecreateDirectory(string dirPath)
 {
     if (SafeDirectory.Exists(dirPath))
     {
         try
         {
             SafeDirectory.Delete(dirPath, true);
         }
         catch (IOException ex)
         {
             LogUtil.LogException(ex);
             if (SafeDirectory.EnumerateFiles(dirPath).Any())
             {
                 throw;
             }
             return; // Can't delete dir, but it is empty => skip it
         }
     }
     SafeDirectory.CreateDirectory(dirPath);
 }
예제 #4
0
        public static void CleanUp()
        {
            SafeDirectory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            LogUtil.LogEvent("clean up");
            try
            {
                foreach (var name in GetProcessesToKill())
                {
                    foreach (var process in Process.GetProcessesByName(name))
                    {
                        LogUtil.LogEvent(string.Format("{0} process kill", name));
                        try
                        {
                            process.Kill();
                            process.WaitForExit(1000); // wait for exit no longer than 1 second
                        }
                        catch (Win32Exception)
                        {
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
                if (SafeDirectory.Exists(WORKING_FOLDER))
                {
                    SafeDirectory.Delete(WORKING_FOLDER, true);
                }
            }
            catch (Exception ex)
            {
                LogUtil.LogException(ex);
                // Do nothing
            }
        }