private static string m_CurrentPath; //取得作业平台 private static string Platform { get { return Environment.OSVersion.Platform.ToString(); } } public static string CurrentPath { get { //RF获取当前目录 if (Platform.Equals("WinCE")) { m_CurrentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); } //获取PC当前目录 else if (Platform.Equals("Win32NT")) { m_CurrentPath = Directory.GetCurrentDirectory(); } return m_CurrentPath; } }
校验有样版本:
/// <summary> /// 检测版本与获取版本信息 /// </summary> /// <returns></returns> public bool HasNewVersion() { bool hasNewVersion = false; if (badnetwork == false) { if (IsUpdateEnabled && DateTime.Compare(DateTime.ParseExact(RemoteDate, "yyyyMMddHHmm", null), DateTime.ParseExact(LocalDate, "yyyyMMddHHmm", null)) > 0) { hasNewVersion = true; } } return hasNewVersion; }
/// <summary> /// 计算文件hash值 /// </summary> /// <param name="path"></param> /// <returns></returns> public static string ChecksumSha1(string path) { byte[] hash = null; using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider(); hash = sha1.ComputeHash(fs); fs.Close(); } return Convert.ToBase64String(hash); }
https://msdn.microsoft.com/en-us/library/aa446487.aspx