예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When the window handle gets created we want to initialize the controls
        /// </summary>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            try
            {
                // Set the Application label to the name of the app
                FwVersionInfoProvider viProvider = new FwVersionInfoProvider(ProductExecutableAssembly, true);
                lblName.Text       = viProvider.ProductName;
                lblAppVersion.Text = viProvider.ApplicationVersion;
                lblFwVersion.Text  = viProvider.FieldWorksVersion;
                lblCopyright.Text  = viProvider.CopyrightString;

                // Set the title bar text
                Text = string.Format(m_sTitleFmt, viProvider.ProductName);

                string strRoot = Path.GetPathRoot(Application.ExecutablePath);

                // Set the memory information
                Win32.MemoryStatus ms = new Win32.MemoryStatus();
                Win32.GlobalMemoryStatus(ref ms);
                edtAvailableMemory.Text = string.Format(m_sAvailableMemoryFmt,
                                                        ms.dwAvailPhys / 1024, ms.dwTotalPhys / 1024);

                // Set the available disk space information.
                uint cSectorsPerCluster = 0, cBytesPerSector = 0, cFreeClusters = 0,
                     cTotalClusters = 0;
                Win32.GetDiskFreeSpace(strRoot, ref cSectorsPerCluster, ref cBytesPerSector,
                                       ref cFreeClusters, ref cTotalClusters);
                uint cbKbFree =
                    (uint)(((Int64)cFreeClusters * cSectorsPerCluster * cBytesPerSector) >> 10);

                edtAvailableDiskSpace.Text =
                    string.Format(m_sAvailableDiskSpaceFmt, cbKbFree, strRoot);
            }
            catch
            {
                // ignore errors
            }
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When the window handle gets created we want to initialize the controls
        /// </summary>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            try
            {
                // Set the Application label to the name of the app
                Assembly assembly = Assembly.GetEntryAssembly();
                string   strRoot;
                object[] attributes;
                if (assembly != null)
                {
                    attributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                    string productName = (attributes != null && attributes.Length > 0) ?
                                         ((AssemblyTitleAttribute)attributes[0]).Title : Application.ProductName;
                    lblName.Text = productName;

                    // Set the application version text
                    attributes = assembly.GetCustomAttributes(
                        typeof(AssemblyFileVersionAttribute), false);
                    string appVersion = (attributes != null && attributes.Length > 0) ?
                                        ((AssemblyFileVersionAttribute)attributes[0]).Version :
                                        Application.ProductVersion;
                    // Extract the fourth (and final) field of the version to get a date value.
                    int ich = appVersion.IndexOf('.');
                    if (ich >= 0)
                    {
                        ich = appVersion.IndexOf('.', ich + 1);
                    }
                    if (ich >= 0)
                    {
                        ich = appVersion.IndexOf('.', ich + 1);
                    }
                    if (ich >= 0)
                    {
                        int iDate = System.Convert.ToInt32(appVersion.Substring(ich + 1));
                        if (iDate > 0)
                        {
                            (this as IFwHelpAbout).ProdOADate = iDate;
                        }
                    }
#if DEBUG
                    lblAppVersion.Text = string.Format(m_sAppVersionFmt, appVersion, m_sProdDate, "(Debug version)");
#else
                    lblAppVersion.Text = string.Format(m_sAppVersionFmt, appVersion, m_sProdDate, "");
#endif

                    // Set the Fieldworks version text
                    attributes = assembly.GetCustomAttributes(
                        typeof(AssemblyInformationalVersionAttribute), false);
                    string fwVersion = (attributes != null && attributes.Length > 0) ?
                                       ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion :
                                       Application.ProductVersion;
                    // Omit the revision number from the suite version string if it's zero.
                    ich = fwVersion.LastIndexOf(".0");
                    if (ich == fwVersion.Length - 2 && ich > fwVersion.IndexOf('.'))
                    {
                        fwVersion = fwVersion.Substring(0, ich);
                    }
                    lblFwVersion.Text = string.Format(m_sFwVersionFmt, fwVersion);

                    // Set the title bar text
                    Text = string.Format(m_sTitleFmt, Application.ProductName);

                    strRoot = Application.ExecutablePath.Substring(0, 2) + "\\";
                }
                else
                {
                    // called from COM client
                    strRoot = m_sDriveLetter + ":\\";
                }

                // Get copyright information from assembly info. By doing this we don't have
                // to update the about dialog each year.
                string copyRight;
                attributes = Assembly.GetExecutingAssembly()
                             .GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes != null && attributes.Length > 0)
                {
                    copyRight = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
                }
                else
                {
                    // if we can't find it in the assembly info, use generic one (which
                    // might be out of date)
                    copyRight = "(C) 2002-2004 SIL International";
                }
                lblCopyright.Text = string.Format(lblCopyright.Text,
                                                  copyRight.Replace("(C)", "©"));

                // Set the memory information
                Win32.MemoryStatus ms = new Win32.MemoryStatus();
                Win32.GlobalMemoryStatus(ref ms);
                edtAvailableMemory.Text = string.Format(m_sAvailableMemoryFmt,
                                                        ms.dwAvailPhys / 1024, ms.dwTotalPhys / 1024);

                // Set the available disk space information.
                uint cSectorsPerCluster = 0, cBytesPerSector = 0, cFreeClusters = 0,
                     cTotalClusters = 0;
                Win32.GetDiskFreeSpace(strRoot, ref cSectorsPerCluster, ref cBytesPerSector,
                                       ref cFreeClusters, ref cTotalClusters);
                uint cbKbFree =
                    (uint)(((Int64)cFreeClusters * cSectorsPerCluster * cBytesPerSector) >> 10);

                edtAvailableDiskSpace.Text =
                    string.Format(m_sAvailableDiskSpaceFmt, cbKbFree, strRoot);

                // Set the Registration Number.
                RegistryKey key    = Registry.LocalMachine.OpenSubKey(@"Software\SIL\FieldWorks");
                string      regNum = null;
                if (key != null)
                {
                    regNum = key.GetValue("FwUserReg") as string;
                    key.Close();
                }

                if (regNum == null || regNum == string.Empty)
                {
                    ResourceManager resources = new ResourceManager(
                        "SIL.FieldWorks.FwCoreDlgs.FwCoreDlgs", Assembly.GetExecutingAssembly());
                    regNum = resources.GetString("kstidUnregistered");
                }

                //lblRegistrationNumber.Text = string.Format(lblRegistrationNumber.Text, regNum);

                // Set expiration date information
                if (m_dropDeadDate.Year > 2999)
                {
                    lblExpirationDate.Visible = false;
                }
                else
                {
                    lblExpirationDate.Text = string.Format(m_sExpirationDateLabelFmt,
                                                           m_dropDeadDate.ToShortDateString());
                }
            }
            catch
            {
                // ignore errors
            }
        }