public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            long fileLength = 0;
            if (!Attributes.ContainsKey("size") || !long.TryParse(Attributes["size"], out fileLength))
                return true;

            string localPath = string.Empty;
            if (Attributes.ContainsKey("localPath"))
                localPath = Attributes["localPath"];
            else if (task != null && task.Attributes.ContainsKey("localPath"))
                localPath = task.Attributes["localPath"];

            if (!File.Exists(localPath))
                return true;

            FileInfo fi = new FileInfo(localPath);

            if (Attributes.ContainsKey("what"))
            {
                switch (Attributes["what"])
                {
                    case "above":
                        return fileLength < fi.Length;
                    case "is":
                        return fileLength == fi.Length;
                }
            }
            return fileLength > fi.Length;
        }
        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            DateTime fileDateTime;
            if (!Attributes.ContainsKey("timestamp") || !DateTime.TryParse(Attributes["timestamp"], out fileDateTime))
                return true;

            string localPath = string.Empty;
            if (Attributes.ContainsKey("localPath"))
                localPath = Attributes["localPath"];
            else if (task != null && task.Attributes.ContainsKey("localPath"))
                localPath = task.Attributes["localPath"];

            if (!File.Exists(localPath))
                return true;

            DateTime localFileDateTime = File.GetLastWriteTime(localPath);
            if (Attributes.ContainsKey("what"))
            {
                switch (Attributes["what"])
                {
                    case "newer":
                        return localFileDateTime > fileDateTime;
                    case "is":
                        return localFileDateTime.Equals(fileDateTime);
                }
            }
            return localFileDateTime < fileDateTime; // == what="older"
        }
        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            if (!Attributes.ContainsKey("version"))
                return true;

            string localPath = string.Empty;
            if (Attributes.ContainsKey("localPath"))
                localPath = Attributes["localPath"];
            else if (task != null && task.Attributes.ContainsKey("localPath"))
                localPath = task.Attributes["localPath"];

            if (!System.IO.File.Exists(localPath))
                return true;

            string versionString = FileVersionInfo.GetVersionInfo(localPath).FileVersion.Replace(", ", ".");
            Version localVersion = new Version(versionString);
            Version updateVersion = new Version(Attributes["version"]);

            if (Attributes.ContainsKey("what"))
            {
                switch (Attributes["what"])
                {
                    case "above":
                        return updateVersion < localVersion;
                    case "is":
                        return updateVersion == localVersion;
                }
            }
            return updateVersion > localVersion;
        }
示例#4
0
        public bool Prepare(NAppUpdate.Framework.Sources.IUpdateSource source)
        {
            if (!Attributes.ContainsKey("localPath"))
                return true; // Errorneous case, but there's nothing to prepare to...

            string fileName;
            if (Attributes.ContainsKey("updateTo"))
                fileName = Attributes["updateTo"];
            else
                fileName = Attributes["localPath"];

            tempFile = null;

            try
            {
                string tempFileLocal = Path.Combine(UpdateManager.Instance.TempFolder, Guid.NewGuid().ToString());
                if (!source.GetData(fileName, UpdateManager.Instance.BaseUrl, ref tempFileLocal))
                    return false;

                tempFile = tempFileLocal;
            }
            catch (Exception ex)
            {
                throw new UpdateProcessFailedException("Couldn't get Data from source", ex);
            }

            if (Attributes.ContainsKey("sha256-checksum"))
            {
                string checksum = Utils.FileChecksum.GetSHA256Checksum(tempFile);
                if (!checksum.Equals(Attributes["sha256-checksum"]))
                    return false;
            }

            return true;
        }
        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            string localPath = string.Empty;
            if (Attributes.ContainsKey("localPath"))
                localPath = Attributes["localPath"];
            else if (task != null && task.Attributes.ContainsKey("localPath"))
                localPath = task.Attributes["localPath"];

            return System.IO.File.Exists(localPath);
        }
示例#6
0
		// TODO: Work with enums on code and Attributes to get a proper and full OS version comparison
		// use http://stackoverflow.com/questions/545666/how-to-translate-ms-windows-os-version-numbers-into-product-names-in-net
		// and http://msdn.microsoft.com/en-us/library/ms724429(VS.85).aspx

        #region IUpdateCondition Members

		public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
		{
			bool is64Bit = Is64BitOperatingSystem();

			if (OsBits == 32 && OsBits != 64)
				return true;

			// OS bitness check, if requested
			if (OsBits == 32 && is64Bit)
				return false;
			if (OsBits == 64 && !is64Bit)
				return false;

			return true;
		}
示例#7
0
        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            // OS bitness check, if requested
            if (Attributes.ContainsKey("bit"))
            {
                bool Is64Bit = Is64BitOperatingSystem();
                if ("32".Equals(Attributes["bit"]) && Is64Bit)
                    return false;
                else if ("64".Equals(Attributes["bit"]) && !Is64Bit)
                    return false;
            }
            return true;

            // TODO: Work with enums on code and Attributes to get a proper and full OS version comparison
            // use http://stackoverflow.com/questions/545666/how-to-translate-ms-windows-os-version-numbers-into-product-names-in-net
            // and http://msdn.microsoft.com/en-us/library/ms724429(VS.85).aspx
            throw new NotImplementedException();
        }
        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            string localPath = string.Empty;
            if (Attributes.ContainsKey("localPath"))
                localPath = Attributes["localPath"];
            else if (task != null && task.Attributes.ContainsKey("localPath"))
                localPath = task.Attributes["localPath"];

            if (!File.Exists(localPath))
                return true;

            if (Attributes.ContainsKey("sha256-checksum"))
            {
                string sha256 = Utils.FileChecksum.GetSHA256Checksum(localPath);
                if (!string.IsNullOrEmpty(sha256) && sha256.Equals(Attributes["sha256-checksum"]))
                    return true;
            }

            // TODO: Support more checksum algorithms (although SHA256 has no collisions, other are more commonly used)

            return false;
        }
示例#9
0
        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            if (ChildConditions == null)
                return true;

            // perform the update if Passed == true
            // otherwise, do not perform the update
            bool Passed = true, firstRun = true;
            foreach (ConditionItem item in ChildConditions)
            {
                // If after the first iteration, accept as fulfilled if we are at an OR clause and the conditions
                // before this checked OK (i.e. update needed)
                if (!firstRun)
                {
                    if (Passed && (item._ConditionType & ConditionType.OR) > 0)
                        return true;
                }
                else { firstRun = false; }

                // Skip all ANDed conditions if some of them failed, until we consume all the conditions
                // or we hit an OR'ed one
                if (!Passed)
                {
                    if ((item._ConditionType & ConditionType.OR) > 0)
                    {
                        bool checkResult = item._Condition.IsMet(task);
                        Passed = (item._ConditionType & ConditionType.NOT) > 0 ? !checkResult : checkResult;
                    }
                }
                else
                {
                    bool checkResult = item._Condition.IsMet(task);
                    Passed = (item._ConditionType & ConditionType.NOT) > 0 ? !checkResult : checkResult;
                }
            }

            return Passed;
        }