示例#1
0
文件: Program.cs 项目: vidarw/RVWorld
        private static void ProcessDir(string dirName)
        {
            Console.WriteLine("Checking Dir : " + dirName);

            DirectoryInfo di = new DirectoryInfo(dirName);

            FileInfo[] fi = di.GetFiles();
            foreach (FileInfo f in fi)
            {
                string filename = f.FullName;
                string ext      = Path.GetExtension(filename)?.ToLower();
                if (!string.IsNullOrEmpty(ext) && (ext == ".zip" || ext == ".7z" || ext == ".iso"))
                {
                    tz.Process(new FileInfo(filename));
                }
            }

            if (_noRecursion)
            {
                return;
            }

            string[] directories = System.IO.Directory.GetDirectories(dirName);
            foreach (string dir in directories)
            {
                ProcessDir(dir);
            }
        }
示例#2
0
        private static void ScanADirNew(string directory)
        {
            _bgw.ReportProgress(0, new bgwText("Scanning Dir : " + directory));
            DirectoryInfo di = new DirectoryInfo(directory);

            FileInfo[] fi = di.GetFiles();

            _bgw.ReportProgress(0, new bgwRange2Visible(true));
            _bgw.ReportProgress(0, new bgwSetRange2(fi.Length));

            for (int j = 0; j < fi.Length; j++)
            {
                if (_bgw.CancellationPending)
                {
                    return;
                }

                FileInfo f = fi[j];
                _bgw.ReportProgress(0, new bgwValue2(j + 1));
                _bgw.ReportProgress(0, new bgwText2(f.Name));

                bool fileFound = ScanAFile(f.FullName, null, f.Name);

                if (fileFound && DelFiles)
                {
                    File.SetAttributes(f.FullName, FileAttributes.Normal);
                    File.Delete(f.FullName);
                }
            }

            DirectoryInfo[] childdi = di.GetDirectories();
            foreach (DirectoryInfo d in childdi)
            {
                if (_bgw.CancellationPending)
                {
                    return;
                }
                ScanADirNew(d.FullName);
            }

            if (directory == "ToSort")
            {
                return;
            }
            if (IsDirectoryEmpty(directory))
            {
                System.IO.DirectoryInfo dii = new System.IO.DirectoryInfo(directory);
                dii.Attributes &= ~FileAttributes.ReadOnly;

                Directory.Delete(directory);
            }
        }
示例#3
0
        private static void ScanRomRoot(string directory)
        {
            _bgw.ReportProgress(0, new bgwText("Scanning Dir : " + directory));
            DirectoryInfo di = new DirectoryInfo(directory);

            FileInfo[] fi = di.GetFiles();

            _bgw.ReportProgress(0, new bgwRange2Visible(true));
            _bgw.ReportProgress(0, new bgwSetRange2(fi.Count()));

            for (int j = 0; j < fi.Count(); j++)
            {
                if (_bgw.CancellationPending)
                {
                    return;
                }

                FileInfo f = fi[j];
                _bgw.ReportProgress(0, new bgwValue2(j));
                _bgw.ReportProgress(0, new bgwText2(f.Name));
                string ext = Path.GetExtension(f.Name);

                if (ext.ToLower() == ".gz")
                {
                    gZip      gZipTest  = new gZip();
                    ZipReturn errorcode = gZipTest.ZipFileOpen(f.FullName);
                    if (errorcode != ZipReturn.ZipGood)
                    {
                        _bgw.ReportProgress(0, new bgwShowError(f.FullName, "gz File corrupt"));
                        if (!Directory.Exists("corrupt"))
                        {
                            Directory.CreateDirectory("corrupt");
                        }
                        File.Move(f.FullName, Path.Combine("corrupt", f.Name));
                        continue;
                    }

                    RvFile tFile = RvFile.fromGZip(f.FullName, gZipTest.ExtraData, gZipTest.CompressedSize);
                    gZipTest.ZipFileClose();

                    FindStatus res = fileneededTest(tFile);

                    if (res != FindStatus.FoundFileInArchive)
                    {
                        if (deep)
                        {
                            gZipTest = new gZip();

                            try
                            {
                                errorcode = gZipTest.ZipFileOpen(f.FullName);
                                if (errorcode == ZipReturn.ZipGood)
                                {
                                    FileScan fs = new FileScan();
                                    List <FileScan.FileResults> gRes = fs.Scan(gZipTest, true, true);
                                    errorcode = gRes[0].FileStatus;
                                    gZipTest.ZipFileClose();
                                }
                            }
                            catch
                            {
                                gZipTest.ZipFileClose();
                                _bgw.ReportProgress(0, new bgwShowError(f.FullName, "gz Crashed Compression"));
                                if (!Directory.Exists("corrupt"))
                                {
                                    Directory.CreateDirectory("corrupt");
                                }
                                File.Move(f.FullName, Path.Combine("corrupt", f.Name));
                                continue;
                            }

                            if (errorcode != ZipReturn.ZipGood)
                            {
                                _bgw.ReportProgress(0, new bgwShowError(f.FullName, "gz File corrupt"));
                                if (!Directory.Exists("corrupt"))
                                {
                                    Directory.CreateDirectory("corrupt");
                                }
                                File.Move(f.FullName, Path.Combine("corrupt", f.Name));
                                continue;
                            }
                        }
                        tFile.DBWrite();
                    }
                }
                if (_bgw.CancellationPending)
                {
                    return;
                }
            }

            DirectoryInfo[] childdi = di.GetDirectories();
            foreach (DirectoryInfo d in childdi)
            {
                if (_bgw.CancellationPending)
                {
                    return;
                }
                ScanRomRoot(d.FullName);
            }
        }
示例#4
0
        public static RvFile FromADir(RvFile dbDir, EScanLevel eScanLevel, ThreadWorker bgw, ref bool fileErrorAbort)
        {
            string    fullDir   = dbDir.FullName;
            DatStatus datStatus = dbDir.IsInToSort ? DatStatus.InToSort : DatStatus.NotInDat;

            RvFile fileDir = new RvFile(FileType.Dir);


            DirectoryInfo oDir = new DirectoryInfo(fullDir);

            DirectoryInfo[] oDirs  = oDir.GetDirectories();
            FileInfo[]      oFiles = oDir.GetFiles();

            // add all the subdirectories into scanDir
            foreach (DirectoryInfo dir in oDirs)
            {
                RvFile tDir = new RvFile(FileType.Dir)
                {
                    Name             = dir.Name,
                    FileModTimeStamp = dir.LastWriteTime
                };
                tDir.SetStatus(datStatus, GotStatus.Got);
                fileDir.ChildAdd(tDir);
            }

            // add all the files into scanDir
            foreach (FileInfo oFile in oFiles)
            {
                string fName = oFile.Name;
                if (fName == "__RomVault.tmp")
                {
                    File.Delete(oFile.FullName);
                    continue;
                }
                string fExt = Path.GetExtension(oFile.Name);

                FileType ft = DBTypeGet.fromExtention(fExt);

                if (Settings.rvSettings.FilesOnly)
                {
                    ft = FileType.File;
                }

                RvFile tFile = new RvFile(ft)
                {
                    Name             = oFile.Name,
                    Size             = (ulong)oFile.Length,
                    FileModTimeStamp = oFile.LastWriteTime
                };
                tFile.FileStatusSet(FileStatus.SizeVerified);
                tFile.SetStatus(datStatus, GotStatus.Got);

                if (eScanLevel == EScanLevel.Level3 && tFile.FileType == FileType.File)
                {
                    FromAFile(tFile, fullDir, eScanLevel, bgw, ref fileErrorAbort);
                }

                fileDir.ChildAdd(tFile);
            }
            return(fileDir);
        }
示例#5
0
文件: Program.cs 项目: vidarw/RVWorld
        private static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("");
                    Console.WriteLine("trrntzip: missing path");
                    Console.WriteLine("Usage: trrntzip [OPTIONS] [PATH/ZIP FILES]");
                    return;
                }

                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i];
                    if (arg.Length < 2)
                    {
                        continue;
                    }
                    if (arg.Substring(0, 1) != "-")
                    {
                        continue;
                    }

                    switch (arg.Substring(1, 1))
                    {
                    case "?":
                        Console.WriteLine($"TorrentZip.Net v{Assembly.GetExecutingAssembly().GetName().Version.ToString(3)}");
                        Console.WriteLine("");
                        Console.WriteLine("Copyright (C) 2020 GordonJ");
                        Console.WriteLine("Homepage : http://www.romvault.com/trrntzip");
                        Console.WriteLine("");
                        Console.WriteLine("Usage: trrntzip [OPTIONS] [PATH/ZIP FILE]");
                        Console.WriteLine("");
                        Console.WriteLine("Options:");
                        Console.WriteLine("");
                        Console.WriteLine("-? : show this help");
                        Console.WriteLine("-s : prevent sub-directory recursion");
                        Console.WriteLine("-f : force re-zip");
                        Console.WriteLine("-c : Check files only do not repair");
                        Console.WriteLine("-l : verbose logging");
                        Console.WriteLine("-v : show version");
                        Console.WriteLine("-g : pause when finished");
                        return;

                    case "s":
                        _noRecursion = true;
                        break;

                    case "f":
                        Trrntzip.Program.ForceReZip = true;
                        break;

                    case "c":
                        Trrntzip.Program.CheckOnly = true;
                        break;

                    case "l":
                        Trrntzip.Program.VerboseLogging = true;
                        string logtime = DateTime.Now.ToString("yyyy-MM-dd-HHmmss");
                        logStream = new StreamWriter($"outlog-{logtime}.txt");
                        break;

                    case "v":
                        Console.WriteLine("TorrentZip v{0}", Assembly.GetExecutingAssembly().GetName().Version);
                        return;

                    case "g":
                        _guiLaunch = true;
                        break;
                    }
                }

                tz = new TorrentZip
                {
                    StatusCallBack    = StatusCallBack,
                    StatusLogCallBack = StatusLogCallBack
                };

                foreach (string tArg in args)
                {
                    string arg = tArg;
                    if (arg.Length < 2)
                    {
                        continue;
                    }
                    if (arg.Substring(0, 1) == "-")
                    {
                        continue;
                    }

                    if (arg.Length > 2 && arg.Substring(0, 2) == ".\\")
                    {
                        arg = arg.Substring(2);
                    }
                    // first check if arg is a directory
                    if (Directory.Exists(arg))
                    {
                        ProcessDir(arg);
                        continue;
                    }

                    // now check if arg is a directory/filename with possible wild cards.

                    string dir = Path.GetDirectoryName(arg);
                    if (string.IsNullOrEmpty(dir))
                    {
                        dir = Environment.CurrentDirectory;
                    }

                    string filename = Path.GetFileName(arg);

                    DirectoryInfo dirInfo  = new DirectoryInfo(dir);
                    FileInfo[]    fileInfo = dirInfo.GetFiles(filename);
                    foreach (FileInfo file in fileInfo)
                    {
                        string ext = Path.GetExtension(file.FullName).ToLower();
                        if (!string.IsNullOrEmpty(ext) && ((ext == ".zip") || (ext == ".7z") || (ext == ".iso")))
                        {
                            tz.Process(new FileInfo(file.FullName));
                        }
                    }
                }

                logStream?.Flush();
                logStream?.Close();
                logStream?.Dispose();
                logStream = null;

                if (_guiLaunch)
                {
                    Console.WriteLine("Complete.");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                logStream?.WriteLine("{0} Exception caught.", e);
                logStream?.Flush();
                logStream?.Close();
                logStream?.Dispose();
                logStream = null;
            }
        }
示例#6
0
        public static RvFile FromADir(RvFile dbDir, EScanLevel eScanLevel, ThreadWorker bgw, ref bool fileErrorAbort)
        {
            string    fullDir   = dbDir.FullName;
            DatStatus datStatus = dbDir.IsInToSort ? DatStatus.InToSort : DatStatus.NotInDat;

            RvFile fileDir = new RvFile(FileType.Dir);


            DirectoryInfo oDir = new DirectoryInfo(fullDir);

            DirectoryInfo[] oDirs  = oDir.GetDirectories();
            FileInfo[]      oFiles = oDir.GetFiles();

            // add all the subdirectories into scanDir
            foreach (DirectoryInfo dir in oDirs)
            {
                RvFile tDir = new RvFile(FileType.Dir)
                {
                    Name             = dir.Name,
                    FileModTimeStamp = dir.LastWriteTime
                };
                tDir.SetStatus(datStatus, GotStatus.Got);
                fileDir.ChildAdd(tDir);
            }

            // add all the files into scanDir
            foreach (FileInfo oFile in oFiles)
            {
                string fName = oFile.Name;
                if (fName == "__RomVault.tmp")
                {
                    File.Delete(oFile.FullName);
                    continue;
                }
                string fExt = Path.GetExtension(oFile.Name);

                FileType ft = DBTypeGet.fromExtention(fExt);

                if (Settings.rvSettings.FilesOnly)
                {
                    ft = FileType.File;
                }

                RvFile tFile = new RvFile(ft)
                {
                    Name             = oFile.Name,
                    Size             = (ulong)oFile.Length,
                    FileModTimeStamp = oFile.LastWriteTime
                };
                tFile.FileStatusSet(FileStatus.SizeVerified);
                tFile.SetStatus(datStatus, GotStatus.Got);

                if (eScanLevel == EScanLevel.Level3 && tFile.FileType == FileType.File)
                {
                    FromAFile(tFile, fullDir, eScanLevel, bgw, ref fileErrorAbort);
                }

                fileDir.ChildAdd(tFile);

                /*
                 * // if we find a zip file add it as zip files.
                 * // else
                 * if (ft == FileType.File)
                 * {
                 * // Scanning a file
                 * //
                 * // Level1 & 2 : (are the same for files) Fully checksum changed only files
                 * // Here we are just getting the TimeStamp of the File, and later
                 * // if the TimeStamp was not matched we will have to read the files CRC, MD5 & SHA1
                 * //
                 * // Level3: Fully checksum everything
                 * // Get everything about the file right here so
                 * // read CRC, MD5 & SHA1
                 *
                 * errorCode = CHD.CheckFile(oFile, out tFile.AltSHA1, out tFile.AltMD5, out tFile.CHDVersion);
                 *
                 * if (errorCode == 0)
                 * {
                 *  if (tFile.AltSHA1 != null)
                 *  {
                 *      tFile.FileStatusSet(FileStatus.AltSHA1FromHeader);
                 *  }
                 *  if (tFile.AltMD5 != null)
                 *  {
                 *      tFile.FileStatusSet(FileStatus.AltMD5FromHeader);
                 *  }
                 *
                 *  // if we are scanning at Level3 then we get all the info here
                 *  if (EScanLevel == EScanLevel.Level3)
                 *  {
                 *      FileResults(fullDir, tFile);
                 *      ChdManCheck(fullDir, tFile);
                 *  }
                 * }
                 * else if (errorCode == 32)
                 * {
                 *  tFile.GotStatus = GotStatus.FileLocked;
                 *  _bgw.Report(new bgwShowError(fullDir, "File Locked"));
                 * }
                 * else
                 * {
                 *  string filename = Path.Combine(fullDir, tFile.Name);
                 *  ReportError.Show("File: " + filename + " Error: " + new Win32Exception(errorCode).Message + ". Scan Aborted.");
                 *  _fileErrorAbort = true;
                 *  return fileDir;
                 * }
                 * }
                 */
            }
            return(fileDir);
        }