Ejemplo n.º 1
0
        void ProcessRemoved(IDictionary <string, Status> statusDic, string x)
        {
            var status = statusDic[x];

            status.Progress = 0;
            status.Action   = RepoStatus.Removing;
            Tools.FileUtil.Ops.DeleteWithRetry(WorkingPath.GetChildFileWithName(x).ToString());
            status.EndOutput();
        }
Ejemplo n.º 2
0
        void RenameExistingObject(IDictionary <string, Status> statusDic, string destName, string srcName)
        {
            var status = statusDic[destName];

            status.Progress = 0;
            status.Action   = RepoStatus.Renaming;
            RenameFilePath(WorkingPath.GetChildFileWithName(srcName), WorkingPath.GetChildFileWithName(destName));
            status.EndOutput();
        }
Ejemplo n.º 3
0
        void ProcessObject(bool skipWhenLocalFileMatches, FileObjectMapping o,
                           ICollection <FileObjectMapping> validObjects)
        {
            if (skipWhenLocalFileMatches)
            {
                // We can also skip objects that already match in the working directory so that we don't waste time on compressing or copying objects needlessly
                // this however could create more bandwidth usage in case the user in the future deletes working files, and tries to get the version again
                // in that case the objects will need to be redownloaded, or at least patched up from other possible available objects.
                var path = WorkingPath.GetChildFileWithName(o.FilePath);
                if (path.Exists &&
                    Repository.GetChecksum(path).Equals(o.Checksum))
                {
                    validObjects.Add(o);
                    if (Common.Flags.Verbose)
                    {
                        MainLog.Logger.Info(
                            $"Marking {o.FilePath} ({o.Checksum}) as valid, because the local object matches");
                    }
                    return;
                }

                var oPath = Repository.GetObjectPath(o.Checksum);
                if (oPath.Exists)
                {
                    validObjects.Add(o);
                    if (Common.Flags.Verbose)
                    {
                        MainLog.Logger.Info(
                            $"Marking {o.FilePath} ({o.Checksum}) as valid, because the packed object exists");
                    }
                    // Don't readd object because we can't validate if the Checksum is in order..
                }
            }
            else
            {
                var ob = Repository.GetObject(o.Checksum);
                if (ob == null)
                {
                    return;
                }
                var oPath = Repository.GetObjectPath(o.Checksum);
                if (oPath.Exists && Repository.GetChecksum(oPath).Equals(ob.ChecksumPack))
                {
                    validObjects.Add(o);
                    if (Common.Flags.Verbose)
                    {
                        MainLog.Logger.Info(
                            $"Marking {o.FilePath} ({o.Checksum}) as valid, because the packed object matches");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        void CopyExistingWorkingFile(IDictionary <string, Status> statusDic, string destName, string srcName)
        {
            var status = statusDic[destName];

            status.Progress = 0;
            status.Action   = RepoStatus.Copying;
            var srcFile  = WorkingPath.GetChildFileWithName(srcName);
            var destFile = WorkingPath.GetChildFileWithName(destName);

            destFile.ParentDirectoryPath.MakeSurePathExists();
            Tools.FileUtil.Ops.CopyWithRetry(srcFile, destFile);
            status.EndOutput();
        }
Ejemplo n.º 5
0
        void ProcessModified(IDictionary <string, Status> statusDic, FileObjectMapping fcm, Action <double, long?> act)
        {
            var status = statusDic[fcm.FilePath];

            status.Progress = 0;
            status.Action   = RepoStatus.Unpacking;
            var destFile   = WorkingPath.GetChildFileWithName(fcm.FilePath);
            var packedFile = Repository.GetObjectPath(fcm.Checksum);

            destFile.ParentDirectoryPath.MakeSurePathExists();

            Tools.Compression.Gzip.UnpackSingleGzip(packedFile, destFile, new StatusWrapper(status, act));
            status.EndOutput();
        }
Ejemplo n.º 6
0
        IAbsoluteFilePath[] GetWorkingPathFiles(bool withRemoval, IOrderedEnumerable <FileObjectMapping> mappings)
        {
            if (!withRemoval)
            {
                return
                    (mappings.Select(x => WorkingPath.GetChildFileWithName(x.FilePath))
                     .Where(x => x.Exists).ToArray());
            }

            var files = Repository.GetFiles(WorkingPath);

            return(files
                   .OrderByDescending(x => Tools.FileUtil.SizePrediction(x.FileName)).ToArray());
        }
Ejemplo n.º 7
0
        Tuple <string, string, string> GetCppInfo()
        {
            var cppFile = WorkingPath.GetChildFileWithName("mod.cpp");

            if (!cppFile.Exists)
            {
                return(new Tuple <string, string, string>(null, null, null));
            }
            var fileContent = File.ReadAllText(cppFile.ToString());

            var p           = new ModCppParser(fileContent);
            var name        = p.GetName();
            var description = p.GetDescription();
            var author      = p.GetAuthor();

            return(Tuple.Create(name, description, author));
        }
Ejemplo n.º 8
0
        void ProcessMissingObject(Package.ObjectMap o, ICollection <Package.ObjectMap> resolvedObjects)
        {
            var f = WorkingPath.GetChildFileWithName(o.FO.FilePath);

            if (!f.Exists)
            {
                return;
            }
            var status = new Status(o.FO.FilePath, StatusRepo)
            {
                Action     = RepoStatus.Packing,
                RealObject = GetObjectPathFromChecksum(o.FO)
            };
            var checksum = Repository.GetChecksum(f);

            this.Logger().Info("Found local previous version file for {0}. Compressing to {1}", o.FO.FilePath,
                               checksum);
            Repository.CompressObject(f, checksum);
            o.ExistingObject = checksum;
            resolvedObjects.Add(o);
            status.EndOutput();
        }