Пример #1
0
            public bool Consume(FileInfo info, out string key, out uint number)
            {
                key    = string.Empty;
                number = 0;
                var ext = info.Extension.ToUpperInvariant();

                if (ext == ".ZIP" || ext == ".RAR")
                {
                    key = info.FullName.ToUpperInvariant();
                    return(true);
                }
                var m = r.Match(info.Name);

                if (!m.Success)
                {
                    return(false);
                }
                string format;

                switch (m.Groups[1].Value[0])
                {
                case 'r':
                    format = ".rar";
                    break;

                case 'z':
                    format = ".zip";
                    break;

                default:
                    throw new NotImplementedException();
                }
                key = Replacements.CombinePath(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name).ToUpperInvariant() + format).ToUpperInvariant();
                return(true);
            }
Пример #2
0
 internal static FileInfo Rename(FileInfo aFile)
 {
     if (renamer.IsMatch(aFile.Name))
     {
         return(aFile);
     }
     aFile.MoveTo(Replacements.CombinePath(aFile.Directory.FullName, String.Format(CultureInfo.InvariantCulture, "unrarit_{0}", aFile.Name)));
     return(aFile);
 }
Пример #3
0
        private void License_Click(object sender, EventArgs e)
        {
            var license = Replacements.CombinePath(Path.GetDirectoryName(Application.ExecutablePath), "license.rtf");

            if (!File.Exists(license))
            {
                MessageBox.Show("License file not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Process.Start(license);
            }
        }
Пример #4
0
        private static DirectoryInfo MakeUnique(DirectoryInfo info)
        {
            if (!info.Exists)
            {
                return(info);
            }
            var baseName = info.Name;

            for (var i = 1; info.Exists; ++i)
            {
                info = new DirectoryInfo(Replacements.CombinePath(info.Parent.FullName, String.Format(CultureInfo.InvariantCulture, "{0}_{1}", baseName, i)));
            }

            return(info);
        }
Пример #5
0
        private static FileInfo MakeUnique(FileInfo info)
        {
            if (!info.Exists)
            {
                return(info);
            }
            var ext      = info.Extension;
            var baseName = info.Name.Substring(0, info.Name.Length - info.Extension.Length);

            for (var i = 1; info.Exists; ++i)
            {
                info = new FileInfo(Replacements.CombinePath(info.DirectoryName, String.Format(CultureInfo.CurrentCulture, "{0}_{1}{2}", baseName, i, ext)));
            }

            return(info);
        }
Пример #6
0
            public bool Consume(FileInfo info, out string key, out uint number)
            {
                key    = string.Empty;
                number = 0;
                var m = r.Match(info.Name);

                if (!m.Success)
                {
                    return(false);
                }
                var val = m.Groups[2].Value;

                if (!uint.TryParse(val, out number))
                {
                    return(false);
                }
                key = Replacements.CombinePath(info.DirectoryName, info.Name.Replace(m.Groups[1].Value, String.Format(
                                                                                         CultureInfo.InvariantCulture,
                                                                                         "part{0}",
                                                                                         1.ToString(new string('0', val.Length), CultureInfo.InvariantCulture)
                                                                                         ))).ToUpperInvariant();

                return(true);
            }
Пример #7
0
            public bool Consume(FileInfo info, out string key, out uint number)
            {
                key    = string.Empty;
                number = 0;
                var m = r.Match(info.Name);

                if (!m.Success)
                {
                    return(false);
                }
                var val = m.Groups[1].Value;

                if (!uint.TryParse(val, out number))
                {
                    return(false);
                }
                key = Replacements.CombinePath(info.DirectoryName, String.Format(
                                                   CultureInfo.InvariantCulture,
                                                   "{0}.{1}1", Path.GetFileNameWithoutExtension(info.Name),
                                                   new string('0', m.Groups[1].Length - 1)
                                                   )).ToUpperInvariant();

                return(true);
            }
Пример #8
0
        private void HandleFile(object o)
        {
            var    task      = o as Task;
            string DestsText = GetDest();

            try {
                Invoke(
                    new SetStatus(status =>
                {
                    task.Item.SubStatus = status;
                }),
                    String.Format(CultureInfo.CurrentCulture, "Opening archive and cracking password: {0}...", task.File.Archive.Name)
                    );
                task.File.Open((passwords as IEnumerable <string>).GetEnumerator());
                Invoke(
                    new SetStatus(status =>
                {
                    task.Item.SubStatus = status;
                }),
                    String.Format(CultureInfo.CurrentCulture, "Extracting: {0}...", task.File.Archive.Name)
                    );


                var paths = new List <string>();
                foreach (IArchiveEntry info in task.File)
                {
                    if (skipper.IsMatch(info.Name))
                    {
                        continue;
                    }
                    paths.Add(info.Name);
                }
                var minPath = CommonDirectoryPrefix(paths);
                if (minPath == null)
                {
                    minPath = string.Empty;
                }
                var basePath = FindBasePath(task, paths.Count, minPath);

                var shouldExtract = false;
                foreach (IArchiveEntry info in task.File)
                {
                    if (skipper.IsMatch(info.Name))
                    {
                        continue;
                    }

                    var name = info.Name;
                    if (!string.IsNullOrEmpty(minPath))
                    {
                        name = name.Substring(minPath.Length + 1);
                    }
                    var rootPath = DestsText;
                    if (task.Item.IsNested)
                    {
                        rootPath = task.File.Archive.Directory.FullName;
                    }
                    var baseDirectory = new DirectoryInfo(Replacements.CombinePath(rootPath, basePath));
                    if (!string.IsNullOrEmpty(basePath) && (OverwriteAction)Config.OverwriteAction == OverwriteAction.RenameDirectory)
                    {
                        baseDirectory = MakeUnique(baseDirectory);
                    }
                    task.Item.BaseDirectory = baseDirectory;

                    FileInfo dest;
                    var      destPath = Replacements.CombinePath(baseDirectory.FullName, name);
                    try {
                        dest = new FileInfo(destPath);
                    }
                    catch (NotSupportedException) {
                        if (!silentSkip.IsMatch(destPath))
                        {
                            Invoke(new InvokeVoidDelegate(() =>
                            {
                                MessageBox.Show(this, String.Format(CultureInfo.CurrentCulture, "Invalid file path: {0}\nSkipping file", destPath));
                            }));
                        }
                        continue;
                    }
                    shouldExtract = SetupExtractDest(task, info, dest);
                }
                if (shouldExtract)
                {
                    task.File.Extract();
                }
            }
            catch (ArchiveException ex) {
                task.Result = ex.Message;
            }
            catch (Exception ex) {
                task.Result = String.Format(CultureInfo.CurrentCulture, "Unexpected: {0} ({1})", ex.Message, typeof(Exception));
            }
            task.Signal.Set();
        }