예제 #1
0
파일: Env.cs 프로젝트: lc11535/SoftEtherVPN
        static void deleteUnusedTempDir()
        {
            DirEntry[] files;

            files = IO.EnumDir(Env.tempDir);

            foreach (DirEntry e in files)
            {
                if (e.IsFolder)
                {
                    if (e.FileName.StartsWith("NET_", StringComparison.CurrentCultureIgnoreCase) && e.FileName.Length == 8)
                    {
                        string dirFullName  = Path.Combine(Env.tempDir, e.fileName);
                        string lockFileName = Path.Combine(dirFullName, "LockFile.dat");
                        bool   deleteNow    = false;

                        try
                        {
                            IO io = IO.FileOpen(lockFileName);
                            io.Close();

                            try
                            {
                                io        = IO.FileOpen(lockFileName, true);
                                deleteNow = true;
                                io.Close();
                            }
                            catch
                            {
                            }
                        }
                        catch
                        {
                            DirEntry[] files2;

                            deleteNow = true;

                            try
                            {
                                files2 = IO.EnumDir(dirFullName);

                                foreach (DirEntry e2 in files2)
                                {
                                    if (e2.IsFolder == false)
                                    {
                                        string fullPath = Path.Combine(dirFullName, e2.fileName);

                                        try
                                        {
                                            IO io2 = IO.FileOpen(fullPath, true);
                                            io2.Close();
                                        }
                                        catch
                                        {
                                            deleteNow = false;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                deleteNow = false;
                            }
                        }

                        if (deleteNow)
                        {
                            IO.DeleteDir(dirFullName, true);
                        }
                    }
                }
            }
        }