public static string GetCurrentVersion() { string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WebHawk.exe"); FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(exePath); return(versionInfo.ToString()); }
/// <summary> /// 获取文件的版本号 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static string GetVersion(string fileName) { if (File.Exists(fileName)) { FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(fileName); return(fileVersion.ToString()); } return(null); }
// <Snippet1> private void GetFileVersion2() { // Get the file version for the notepad. FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe"); // Print all the version information. textBox1.Text = myFileVersionInfo.ToString(); }
// Additional Tests Wanted: // [] File exists but we don't have permission to read it // [] DLL has unknown codepage info // [] DLL language/codepage is 8-hex-digits (locale > 0x999) (different codepath) private static void VerifyVersionInfo(String filePath, MyFVI expected) { Console.WriteLine("Testing binary: " + filePath); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(filePath); Console.WriteLine("Got the fvi: " + fvi); TestStringProperty("Comments", fvi.Comments, expected.Comments); TestStringProperty("CompanyName", fvi.Comments, expected.Comments); TestProperty <int>("FileBuildPart", fvi.FileBuildPart, expected.FileBuildPart); TestStringProperty("FileDescription", fvi.FileDescription, expected.FileDescription); TestProperty <int>("FileMajorPart", fvi.FileMajorPart, expected.FileMajorPart); TestProperty <int>("FileMinorPart", fvi.FileMinorPart, expected.FileMinorPart); TestStringProperty("FileName", fvi.FileName, expected.FileName); TestProperty <int>("FilePrivatePart", fvi.FilePrivatePart, expected.FilePrivatePart); TestStringProperty("FileVersion", fvi.FileVersion, expected.FileVersion); TestStringProperty("InternalName", fvi.InternalName, expected.InternalName); TestProperty <bool>("IsDebug", fvi.IsDebug, expected.IsDebug); TestProperty <bool>("IsPatched", fvi.IsPatched, expected.IsPatched); TestProperty <bool>("IsPrivateBuild", fvi.IsPrivateBuild, expected.IsPrivateBuild); TestProperty <bool>("IsPreRelease", fvi.IsPreRelease, expected.IsPreRelease); TestProperty <bool>("IsSpecialBuild", fvi.IsSpecialBuild, expected.IsSpecialBuild); TestStringProperty("Language", fvi.Language, expected.Language, expected.Language2, false); TestStringProperty("LegalCopyright", fvi.LegalCopyright, expected.LegalCopyright, false); TestStringProperty("LegalTrademarks", fvi.LegalTrademarks, expected.LegalTrademarks); TestStringProperty("OriginalFilename", fvi.OriginalFilename, expected.OriginalFilename); TestStringProperty("PrivateBuild", fvi.PrivateBuild, expected.PrivateBuild); TestProperty <int>("ProductBuildPart", fvi.ProductBuildPart, expected.ProductBuildPart); TestProperty <int>("ProductMajorPart", fvi.ProductMajorPart, expected.ProductMajorPart); TestProperty <int>("ProductMinorPart", fvi.ProductMinorPart, expected.ProductMinorPart); TestStringProperty("ProductName", fvi.ProductName, expected.ProductName, false); TestProperty <int>("ProductPrivatePart", fvi.ProductPrivatePart, expected.ProductPrivatePart); TestStringProperty("ProductVersion", fvi.ProductVersion, expected.ProductVersion, false); TestStringProperty("SpecialBuild", fvi.SpecialBuild, expected.SpecialBuild); //ToString String nl = "\r\n"; TestStringProperty("ToString()", fvi.ToString(), "File: " + fvi.FileName + nl + "InternalName: " + fvi.InternalName + nl + "OriginalFilename: " + fvi.OriginalFilename + nl + "FileVersion: " + fvi.FileVersion + nl + "FileDescription: " + fvi.FileDescription + nl + "Product: " + fvi.ProductName + nl + "ProductVersion: " + fvi.ProductVersion + nl + "Debug: " + fvi.IsDebug.ToString() + nl + "Patched: " + fvi.IsPatched.ToString() + nl + "PreRelease: " + fvi.IsPreRelease.ToString() + nl + "PrivateBuild: " + fvi.IsPrivateBuild.ToString() + nl + "SpecialBuild: " + fvi.IsSpecialBuild.ToString() + nl + "Language: " + fvi.Language + nl, false); }
// Additional Tests Wanted: // [] File exists but we don't have permission to read it // [] DLL has unknown codepage info // [] DLL language/codepage is 8-hex-digits (locale > 0x999) (different codepath) private void VerifyVersionInfo(string filePath, MyFVI expected) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(filePath); Assert.Equal(expected.Comments, fvi.Comments); Assert.Equal(expected.CompanyName, fvi.CompanyName); Assert.Equal(expected.FileBuildPart, fvi.FileBuildPart); Assert.Equal(expected.FileDescription, fvi.FileDescription); Assert.Equal(expected.FileMajorPart, fvi.FileMajorPart); Assert.Equal(expected.FileMinorPart, fvi.FileMinorPart); Assert.Equal(expected.FileName, fvi.FileName); Assert.Equal(expected.FilePrivatePart, fvi.FilePrivatePart); Assert.Equal(expected.FileVersion, fvi.FileVersion); Assert.Equal(expected.InternalName, fvi.InternalName); Assert.Equal(expected.IsDebug, fvi.IsDebug); Assert.Equal(expected.IsPatched, fvi.IsPatched); Assert.Equal(expected.IsPrivateBuild, fvi.IsPrivateBuild); Assert.Equal(expected.IsPreRelease, fvi.IsPreRelease); Assert.Equal(expected.IsSpecialBuild, fvi.IsSpecialBuild); Assert.Contains(fvi.Language, new[] { expected.Language, expected.Language2 }); Assert.Equal(expected.LegalCopyright, fvi.LegalCopyright); Assert.Equal(expected.LegalTrademarks, fvi.LegalTrademarks); Assert.Equal(expected.OriginalFilename, fvi.OriginalFilename); Assert.Equal(expected.PrivateBuild, fvi.PrivateBuild); Assert.Equal(expected.ProductBuildPart, fvi.ProductBuildPart); Assert.Equal(expected.ProductMajorPart, fvi.ProductMajorPart); Assert.Equal(expected.ProductMinorPart, fvi.ProductMinorPart); Assert.Equal(expected.ProductName, fvi.ProductName); Assert.Equal(expected.ProductPrivatePart, fvi.ProductPrivatePart); Assert.Equal(expected.ProductVersion, fvi.ProductVersion); Assert.Equal(expected.SpecialBuild, fvi.SpecialBuild); //ToString string nl = Environment.NewLine; Assert.Equal("File: " + fvi.FileName + nl + "InternalName: " + fvi.InternalName + nl + "OriginalFilename: " + fvi.OriginalFilename + nl + "FileVersion: " + fvi.FileVersion + nl + "FileDescription: " + fvi.FileDescription + nl + "Product: " + fvi.ProductName + nl + "ProductVersion: " + fvi.ProductVersion + nl + "Debug: " + fvi.IsDebug.ToString() + nl + "Patched: " + fvi.IsPatched.ToString() + nl + "PreRelease: " + fvi.IsPreRelease.ToString() + nl + "PrivateBuild: " + fvi.IsPrivateBuild.ToString() + nl + "SpecialBuild: " + fvi.IsSpecialBuild.ToString() + nl + "Language: " + fvi.Language + nl, fvi.ToString()); }
private static void DumpReport(Exception exception) { StringWriter stringWriter = new StringWriter((IFormatProvider)CultureInfo.InvariantCulture); stringWriter.WriteLine("Microsoft® Expression® crash report:"); stringWriter.WriteLine(); DateTime now = DateTime.Now; stringWriter.WriteLine("Date: " + now.Year.ToString("D4", (IFormatProvider)CultureInfo.InvariantCulture) + "-" + now.Month.ToString("D2", (IFormatProvider)CultureInfo.InvariantCulture) + "-" + now.Day.ToString("D2", (IFormatProvider)CultureInfo.InvariantCulture) + " " + now.Hour.ToString("D2", (IFormatProvider)CultureInfo.InvariantCulture) + "-" + now.Minute.ToString("D2", (IFormatProvider)CultureInfo.InvariantCulture) + "-" + now.Second.ToString("D2", (IFormatProvider)CultureInfo.InvariantCulture)); stringWriter.WriteLine("User: "******"@" + Environment.MachineName); stringWriter.WriteLine(); stringWriter.WriteLine("Application Version: " + typeof(ExceptionHandler).Assembly.GetName().Version.ToString()); stringWriter.WriteLine("Operating System Version: " + Environment.OSVersion.ToString()); stringWriter.WriteLine("Common Language Runtime Version: " + Environment.Version.ToString()); stringWriter.WriteLine(); stringWriter.WriteLine(exception.ToString()); stringWriter.WriteLine(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { stringWriter.WriteLine(assembly.GetName().FullName); } stringWriter.WriteLine(); foreach (Assembly assembly in assemblies) { bool flag = false; try { if (assembly.Location.Length != 0) { FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); stringWriter.Write(versionInfo.ToString()); flag = true; } } catch { } if (!flag) { stringWriter.WriteLine(assembly.ToString()); } stringWriter.WriteLine(); } string text = stringWriter.ToString(); stringWriter.Close(); Dump.Write(text); }
[WindowsFact] // ModuleInfo.Version only supports native modules at the moment public void FileVersionInfoVersionTest() { bool found = false; // Make sure we never return different values for the version using DataTarget dt = TestTargets.Types.LoadFullDump(); foreach (ModuleInfo module in dt.EnumerateModules()) { if (!module.IsManaged) { continue; } PEImage img = module.GetPEImage(); Assert.NotNull(img); FileVersionInfo fileVersionInfo = img.GetFileVersionInfo(); if (fileVersionInfo != null) { VersionInfo moduleVersion = module.Version; Assert.Equal(moduleVersion, fileVersionInfo.VersionInfo); found = true; } if (Path.GetFileNameWithoutExtension(module.FileName).Equals("types", StringComparison.OrdinalIgnoreCase)) { Assert.Equal("1.2.3.4", fileVersionInfo.FileVersion); Assert.Equal("1.2.3.4", fileVersionInfo.VersionInfo.ToString()); Assert.Equal("1.2.3.4", fileVersionInfo.ToString()); Assert.Equal(1, fileVersionInfo.VersionInfo.Major); Assert.Equal(2, fileVersionInfo.VersionInfo.Minor); Assert.Equal(3, fileVersionInfo.VersionInfo.Revision); Assert.Equal(4, fileVersionInfo.VersionInfo.Patch); } } Assert.True(found, "Did not find any modules with non-null GetFileVersionInfo to compare"); }
public void FileVersion(string assemblyName) { Assembly testAssembly = System.Reflection.Assembly.Load(assemblyName); FileVersionInfo actual = FileVersionInfo.GetVersionInfo(testAssembly.Location); string versionString = GetFileFromRoot(s_gitInfoFile); if (versionString.IndexOf("-") is int idx && idx > 0) { versionString = versionString.Substring(0, idx); } Version expected = Version.Parse(versionString); Assert.AreEqual(expected.Major, actual.FileMajorPart, $"FileMajorPart is wrong. {actual.ToString()}"); Assert.AreEqual(expected.Minor, actual.FileMinorPart, $"FileMinorPart is wrong. {actual.ToString()}"); // Fails locally //Assert.AreEqual(expected.Build, actual.FileBuildPart, $"FileBuildPart is wrong. {actual.ToString()}"); //We need to enable this // Assert.AreEqual(ThisAssembly.Git.Commits, version.FilePrivatePart); Assert.AreEqual(s_productName, actual.ProductName); Assert.AreEqual(s_company, actual.CompanyName); }
private void lvNamespaces_SelectionChanged(object sender, SelectionChangedEventArgs e) { Namespaces namespaces; try { #region //if (lvNamespaces.SelectedItems.Count > 0) //{ // for (int i = 0; i < lvNamespaces.SelectedItems.Count; i++) // { // if (lvNamespaces.SelectedItems[i].Selected) // { // int i2 = lvNamespaces.SelectedItems[i].Index; // item = lvNamespaces.Items[i2].Text; // //sColl.Add(item); // } // } //} //Namespaces namespaces = (Namespaces)lvNamespaces.SelectedItems[aq]; //if (lvNamespaces.SelectedItems.Count > 0) //{ // for (int lcount = 0; lcount <= lvNamespaces.Items.Count - 1; lcount++) // { // if (lvNamespaces.Items[lcount]. == true) // { // var2 = lcount; // break; // } // } //} //string a = lvNamespaces.SelectedItems.Count.ToString(); //int b = Convert.ToInt32(a); // int aq = lvNamespaces.SelectedIndex; #endregion namespaces = (Namespaces)lvNamespaces.SelectedItem;//SelectedItems[0]; //System.Windows.MessageBox.Show(namespaces.Namespace); if (namespaces != null) { namespacecombined = filepath + '\\' + namespaces.Namespace; if (namespacecombined != null && namespacecombined.Length > 0) { //getfileinformation = namespacecombined; // if (getfileinformation != null && getfileinformation.Length > 0) // { FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(namespacecombined); // txtblockDescription.Text = myFileVersionInfo.ToString(); //MessageBox.Show(myFileVersionInfo.ToString()); Namespaces person = new Namespaces { Property = myFileVersionInfo.ToString() }; this.DataContext = person; //} } else { txtblockDescription.Text = ""; } } else { txtblockDescription.Text = ""; } #region //if (lvNamespaces.SelectedIndex.Count <= 0) //{ // return; //} //ListItem vae intselectedindex = lvNamespaces.SelectedIndex[0];//SelectedIndices[0]; //if (intselectedindex >= 0) //{ // String text = listView1.Items[intselectedindex].Text; // //do something // //MessageBox.Show(listView1.Items[intselectedindex].Text); //} //var chapters = new List<Namespaces>(); //foreach (var item in lvNamespaces.SelectedItems) // //.Add((Namespaces)item); //this.txtblockDescription.Text = this.lvNamespaces.Items[lvNamespaces.SelectedIndex].ToString().Trim(); //if (lvNamespaces.SelectedItems.Count > 0) // lvNamespaces.SelectedItems[0].ToString(); //if (lvNamespaces.SelectedIndex >= 0) //{ // var selectedItems = lvNamespaces.SelectedItems; // foreach (Namespaces selectedItem in selectedItems) // { // lvNamespaces.Items.Remove(selectedItem); // break; // } //} //txtblockDescription.Text = updateCartTotal().ToString(); // String text = lvNamespaces.SelectedItems[0].ToString(); //int aq = lvNamespaces.SelectedIndex; //DataRowView CompRow1 = lvNamespaces.Items.GetItemAt(aq) as DataRowView; //if (e.AddedItems != null && e.AddedItems.Count > 0) //{ // DataRow selectedRow = e.AddedItems[0] as DataRow; // if (selectedRow != null) // { // object[] items = selectedRow.ItemArray; // //to sth with these items... // } //} ////int //int SComp = lvNamespaces.SelectedIndex; //DataRowView CompRow = lvNamespaces.Items.GetItemAt(SComp) as DataRowView; ////string ka = Convert.ToString(CompRow["Namespace"]); //ListViewItem namespaceselectedItem = ((sender as ListView).SelectedItem as ListViewItem); //ListView lv = e.OriginalSource as ListView; //ListViewItem lvi = lv.SelectedItem as ListViewItem; //// versionselecteditem = cmbboxVersion.SelectedItem.ToString(); //// namespacecombined = filepath + '\\' + versionselecteditem; //if (lvNamespaces.SelectedItem != null) // // namespaceselectedItem = e.AddedItems[0].ToString(); // //namespaceselectedItem = lvNamespaces.SelectedItem.ToString(); // // namespaceselectedItem = lvNamespaces.SelectedItem.ToString(); ////ListView item = lvNamespaces.SelectedItems[0]; //////fill the text boxes ////textBoxID.Text = item.Text; ////textBoxName.Text = item.SubItems[0].Text; ////textBoxPhone.Text = item.SubItems[1].Text; ////textBoxLevel.Text = item.SubItems[2].Text; //getfileinformation = filepath + '\\' + namespaceselectedItem; //// string d = System.IO.Path.GetDirectoryName(x); //if (namespaceselectedItem != null)// && namespaceselectedItem.Length > 0 //{ // FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(getfileinformation); // //MessageBox.Show(myFileVersionInfo.ToString()); // txtblockDescription.Text = myFileVersionInfo.ToString(); //} //else // txtblockDescription.Text = ""; #endregion } catch (Exception) { throw; } finally { //namespaces = null; //FirstEntry = false; //lvNamespaces.SelectedItem = null; } }
static int Main() { List <int> UIRunningInSession = new List <int>(); const string PackageID = "Vulpes-SDCA1-Update"; string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (dir.EndsWith("\\") == false) { dir += "\\"; } string pkgfile = dir + "agentupdate.foxpkg"; if (File.Exists(pkgfile) == false) { return(1); } PackageInstaller pkgi = new PackageInstaller(); string Error; if (pkgi.PackageInfo(pkgfile, null, out Error) == false) { FoxEventLog.WriteEventLog("Self-Update: Error reading package file " + pkgfile + ": " + Error, EventLogEntryType.Error); return(2); } if (pkgi.PackageInfoData.PackageID != PackageID) { FoxEventLog.WriteEventLog("Self-Update: PackageID mismatch on file " + pkgfile, EventLogEntryType.Error); return(3); } FileVersionInfo fv = FileVersionInfo.GetVersionInfo(dir + "FoxSDC_Agent.exe"); Int64 sdcversion = Convert.ToInt64(fv.FileBuildPart.ToString("0000") + fv.FilePrivatePart.ToString("0000")); if (pkgi.PackageInfoData.VersionID <= sdcversion) { FoxEventLog.WriteEventLog("Self-Update: Version on package is same or older than installed for file " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + fv.ToString(), EventLogEntryType.Error); return(4); } ServiceController svc = new ServiceController("FoxSDCA"); try { svc.Stop(); } catch { } int i = 0; do { i++; if (i > 120 * 4) { break; } svc.Refresh(); Thread.Sleep(1000); } while (svc.Status != ServiceControllerStatus.Stopped); #region Kill Processes foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent_ui.exe") { if (UIRunningInSession.Contains(proc.SessionId) == false) { UIRunningInSession.Add(proc.SessionId); } proc.Kill(); } } catch { } } foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_applyusersettings.exe") { proc.Kill(); } } catch { } } foreach (Process proc in Process.GetProcesses()) { try { if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent.exe") { proc.Kill(); } } catch { } } #endregion FoxEventLog.WriteEventLog("Self-Update: Updating from " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + sdcversion.ToString(), EventLogEntryType.Information); PKGStatus status; PKGRecieptData reciept; if (pkgi.InstallPackage(pkgfile, null, PackageInstaller.InstallMode.Test, false, out Error, out status, out reciept, "FoxSDC_Selfupdate.exe") == false) { FoxEventLog.WriteEventLog("Self-Update: Error testing the package file " + pkgfile + ": " + Error, EventLogEntryType.Error); svc = new ServiceController("FoxSDCA"); svc.Start(); return(5); } if (pkgi.InstallPackage(pkgfile, null, PackageInstaller.InstallMode.Install, false, out Error, out status, out reciept, "FoxSDC_Selfupdate.exe") == false) { FoxEventLog.WriteEventLog("Self-Update: Error installing the package file " + pkgfile + ": " + Error, EventLogEntryType.Error); svc = new ServiceController("FoxSDCA"); svc.Start(); return(6); } FoxEventLog.WriteEventLog("Self-Update: Completed updating from " + pkgfile + "\r\nPackage: " + pkgi.PackageInfoData.VersionID.ToString() + "\r\nProgram: " + sdcversion.ToString(), EventLogEntryType.Information); svc = new ServiceController("FoxSDCA"); svc.Start(); try { File.Delete(pkgfile); } catch { CommonUtilities.PendingMove(pkgfile, null); } SessionStarter.StartProgramInSessions(dir.ToLower() + "foxsdc_agent_ui.exe", UIRunningInSession); return(0); }