예제 #1
0
        public bool IsMet(IUpdateTask task)
        {
            var localPath = !string.IsNullOrEmpty(LocalPath)
                                ? LocalPath
                                : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string;

            // local path is invalid, we can't check for anything so we will return as if the condition was met
            if (string.IsNullOrEmpty(localPath))
            {
                return(true);
            }

            // if the local file does not exist, checksums don't match vacuously
            if (!File.Exists(localPath))
            {
                return(false);
            }

            if ("sha256".Equals(ChecksumType, StringComparison.InvariantCultureIgnoreCase))
            {
                var sha256 = FileChecksum.GetSHA256Checksum(localPath);
                if (!string.IsNullOrEmpty(sha256) && sha256.Equals(Checksum, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }

            // TODO: Support more checksum algorithms (although SHA256 isn't known to have collisions, other are more commonly used)

            return(false);
        }
예제 #2
0
파일: FileInfoEx.cs 프로젝트: wuxingya/Wox
 public FileInfoEx(string fileName, int rootDirectoryLength)
 {
     myFileInfo    = new FileInfo(fileName);
     myFileVersion = FileVersionInfo.GetVersionInfo(fileName).FileVersion;
     if (myFileVersion != null)
     {
         myFileVersion = myFileVersion.Replace(", ", ".");
     }
     myHash       = FileChecksum.GetSHA256Checksum(fileName);
     RelativeName = fileName.Substring(rootDirectoryLength + 1);
 }
예제 #3
0
        public override void Prepare(Sources.IUpdateSource source)
        {
            if (string.IsNullOrEmpty(LocalPath))
            {
                UpdateManager.Instance.Logger.Log(Logger.SeverityLevel.Warning,
                                                  "FileUpdateTask: LocalPath is empty, task is a noop");
                return;                 // Errorneous case, but there's nothing to prepare to, and by default we prefer a noop over an error
            }

            string fileName;

            if (!string.IsNullOrEmpty(UpdateTo))
            {
                fileName = UpdateTo;
            }
            else
            {
                fileName = LocalPath;
            }

            _tempFile = null;

            string baseUrl       = UpdateManager.Instance.BaseUrl;
            string tempFileLocal = Path.Combine(UpdateManager.Instance.Config.TempFolder, Guid.NewGuid().ToString());

            UpdateManager.Instance.Logger.Log("FileUpdateTask: Downloading {0} with BaseUrl of {1} to {2}", fileName, baseUrl,
                                              tempFileLocal);

            if (!source.GetData(fileName, baseUrl, OnProgress, ref tempFileLocal))
            {
                throw new UpdateProcessFailedException("FileUpdateTask: Failed to get file from source");
            }

            _tempFile = tempFileLocal;
            if (_tempFile == null)
            {
                throw new UpdateProcessFailedException("FileUpdateTask: Failed to get file from source");
            }

            if (!string.IsNullOrEmpty(Sha256Checksum))
            {
                string checksum = FileChecksum.GetSHA256Checksum(_tempFile);
                if (!checksum.Equals(Sha256Checksum))
                {
                    throw new UpdateProcessFailedException(string.Format(
                                                               "FileUpdateTask: Checksums do not match; expected {0} but got {1}", Sha256Checksum, checksum));
                }
            }

            _destinationFile = Path.Combine(Path.GetDirectoryName(UpdateManager.Instance.ApplicationPath), LocalPath);
            UpdateManager.Instance.Logger.Log("FileUpdateTask: Prepared successfully; destination file: {0}", _destinationFile);
        }
예제 #4
0
        public FileInfoEx(string fileName, int rootDirLength)
        {
            myFileInfo = new FileInfo(fileName);
            var verInfo = FileVersionInfo.GetVersionInfo(fileName);

            if (myFileVersion != null)
            {
                myFileVersion = new System.Version(verInfo.FileMajorPart, verInfo.FileMinorPart, verInfo.FileBuildPart, verInfo.FilePrivatePart).ToString();
            }
            myHash = FileChecksum.GetSHA256Checksum(fileName);

            RelativeName = fileName.Substring(rootDirLength);
        }