Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Return true if the backup should be canceled to allow the user to correct the
        /// comment or something because there are problems with the file name. May show various
        /// messages to the user.
        /// </summary>
        /// <remarks>Ideally, showing the message boxes should be done directly from the dialog
        /// box, not here in the Presenter.</remarks>
        /// ------------------------------------------------------------------------------------
        internal bool FileNameProblems(Form messageBoxOwner)
        {
            var versionInfoProvider = new VersionInfoProvider(Assembly.GetExecutingAssembly(), false);
            var settings            = new BackupProjectSettings(m_cache, m_backupProjectView, FwDirectoryFinder.DefaultBackupDirectory,
                                                                versionInfoProvider.MajorVersion);

            settings.DestinationFolder = m_backupProjectView.DestinationFolder;
            if (settings.AdjustedComment.Trim() != settings.Comment.TrimEnd())
            {
                string displayComment;
                string format = FwCoreDlgs.ksCharactersNotPossible;
                if (File.Exists(settings.ZipFileName))
                {
                    format = FwCoreDlgs.ksCharactersNotPossibleOverwrite;
                }
                displayComment = settings.Comment.Trim();
                if (displayComment.Length > 255)
                {
                    displayComment = displayComment.Substring(0, 255) + "...";
                }


                string msg = string.Format(format, settings.AdjustedComment, displayComment);
                return(MessageBox.Show(messageBoxOwner, msg, FwCoreDlgs.ksCommentWillBeAltered, MessageBoxButtons.OKCancel,
                                       File.Exists(settings.ZipFileName) ? MessageBoxIcon.Warning : MessageBoxIcon.Information)
                       == DialogResult.Cancel);
            }
            if (File.Exists(settings.ZipFileName))
            {
                string msg = string.Format(FwCoreDlgs.ksOverwriteDetails, settings.ZipFileName);
                return(MessageBox.Show(messageBoxOwner, msg, FwCoreDlgs.ksOverwrite, MessageBoxButtons.OKCancel,
                                       MessageBoxIcon.Warning) == DialogResult.Cancel);
            }
            return(false);            // no problems!
        }
Exemple #2
0
 /// <summary>
 /// Migrates old dictionary and reversal configurations if there are not already new dictionary and reversal configurations.
 /// </summary>
 public void MigrateOldConfigurationsIfNeeded()
 {
     using (m_logger = new SimpleLogger())
     {
         try
         {
             var versionProvider = new VersionInfoProvider(Assembly.GetExecutingAssembly(), true);
             // Further migration changes (especially Label changes) may need changes in multiple migrators:
             foreach (var migrator in m_migrators)
             {
                 migrator.MigrateIfNeeded(m_logger, m_propertyTable, versionProvider.ApplicationVersion);
             }
             CreateProjectCustomCssIfNeeded(m_propertyTable);
         }
         finally
         {
             if (m_logger.HasContent)
             {
                 var configurationDir = DictionaryConfigurationListener.GetProjectConfigurationDirectory(m_propertyTable,
                                                                                                         DictionaryConfigurationListener.DictionaryConfigurationDirectoryName);
                 Directory.CreateDirectory(configurationDir);
                 File.AppendAllText(Path.Combine(configurationDir, "ConfigMigrationLog.txt"), m_logger.Content);
             }
         }
     }
     m_logger = null;
 }
Exemple #3
0
        /// <summary>
        /// When the window handle gets created we want to initialize the controls
        /// </summary>
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            try
            {
                // Set the Application label to the name of the app
                var viProvider = new VersionInfoProvider(ProductExecutableAssembly, true);
                lblName.Text       = viProvider.ProductName;
                lblAppVersion.Text = viProvider.ApplicationVersion;
                lblFwVersion.Text  = viProvider.MajorVersion;

                // List the copyright information
                var acknowlegements = AcknowledgementsProvider.CollectAcknowledgements();
                var list            = acknowlegements.Keys.ToList();
                list.Sort();
                var text = viProvider.CopyrightString + Environment.NewLine + viProvider.LicenseString + Environment.NewLine + viProvider.LicenseURL;
                foreach (var key in list)
                {
                    text += "\r\n" + "\r\n" + key + "\r\n" + acknowlegements[key].Copyright + " " + acknowlegements[key].Url + " " + acknowlegements[key].LicenseUrl;
                }
                txtCopyright.Text = text;

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

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

                if (MiscUtils.IsUnix)
                {
                    return;
                }

                // Set the memory information
                var memStatEx = new Win32.MemoryStatusEx();
                memStatEx.dwLength = (uint)Marshal.SizeOf(memStatEx);
                Win32.GlobalMemoryStatusEx(ref memStatEx);
                edtAvailableMemory.Text = string.Format(m_sAvailableMemoryFmt, memStatEx.ullAvailPhys / BytesPerMiB, memStatEx.ullTotalPhys / BytesPerMiB);

                // Set the available disk space information.
                ulong _, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
                Win32.GetDiskFreeSpaceEx(strRoot, out _, out lpTotalNumberOfBytes, out lpTotalNumberOfFreeBytes);
                var gbFree  = lpTotalNumberOfFreeBytes / BytesPerGiB;
                var gbTotal = lpTotalNumberOfBytes / BytesPerGiB;
                edtAvailableDiskSpace.Text = string.Format(m_sAvailableDiskSpaceFmt, gbFree, gbTotal, strRoot);
            }
            catch (Exception ex)
            {
                Console.WriteLine("HelpAbout ignoring exception: " + ex);
            }
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Protected constructor for initialization in tests
 /// </summary>
 /// <param name="projectsRootFolder">The root folder for projects (typically the
 /// default, but if these setings represent a project elsewhere, then this will be the
 /// root folder for this project).</param>
 /// <param name="projectName">Name of the project.</param>
 /// <param name="linkedFilesPath">The linked files path.</param>
 /// <param name="sharedProjectFolder">A possibly alternate project path that
 /// should be used for things that should be shared.</param>
 /// <param name="originalProjType">Type of the project before converting for backup.</param>
 /// <param name="destFolder">The destination folder.</param>
 /// ------------------------------------------------------------------------------------
 protected BackupProjectSettings(string projectsRootFolder, string projectName,
                                 string linkedFilesPath, string sharedProjectFolder, FDOBackendProviderType originalProjType, string destFolder) :
     base(projectsRootFolder, linkedFilesPath, sharedProjectFolder)
 {
     ProjectName = projectName;
     DbVersion   = FDOBackendProvider.ModelVersion;
     FwVersion   = new VersionInfoProvider(Assembly.GetExecutingAssembly(), false).MajorVersion;
     // For DB4o projects, we need to convert them over to XML. We can't put the
     // converted project in the same directory so we convert them to a temporary
     // directory (see FWR-2813).
     DatabaseFolder    = (originalProjType == FDOBackendProviderType.kXML || originalProjType == FDOBackendProviderType.kSharedXML) ? ProjectPath : Path.GetTempPath();
     DestinationFolder = destFolder;
     BackupTime        = DateTime.Now;
 }
Exemple #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Prepares the selected files to be uploaded to REAP using RAMP.
        /// </summary>
        /// <param name="owner">RAMP dialog owner</param>
        /// <param name="dialogFont">RAMP dialog font (for localization and consistency)</param>
        /// <param name="localizationDialogIcon"></param>
        /// <param name="filesToArchive"></param>
        /// <param name="propertyTable"></param>
        /// <param name="thisapp"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public bool ArchiveNow(Form owner, Font dialogFont, Icon localizationDialogIcon,
                               IEnumerable <string> filesToArchive, PropertyTable propertyTable, FwApp thisapp, LcmCache cache)
        {
            var viProvider             = new VersionInfoProvider(Assembly.LoadFile(thisapp.ProductExecutableFile), false);
            WritingSystemManager wsMgr = cache.ServiceLocator.WritingSystemManager;
            var appName   = thisapp.ApplicationName;
            var title     = cache.LanguageProject.ShortName;
            var uiLocale  = wsMgr.Get(cache.DefaultUserWs).IcuLocale;
            var projectId = cache.LanguageProject.ShortName;

            var model = new RampArchivingDlgViewModel(Application.ProductName, title, projectId, /*appSpecificArchivalProcessInfo:*/ string.Empty, SetFilesToArchive(filesToArchive), GetFileDescription);

            // image files should be labeled as Graphic rather than Photograph (the default).
            model.ImagesArePhotographs = false;

            // show the count of media files, not the duration
            model.ShowRecordingCountNotLength = true;

            // set the general description, in each available language
            IMultiString descr        = cache.LanguageProject.Description;
            var          descriptions = new Dictionary <string, string>();

            foreach (int wsid in descr.AvailableWritingSystemIds)
            {
                var descrText = descr.get_String(wsid).Text;
                if ((!string.IsNullOrEmpty(descrText)) && (descrText != "***"))
                {
                    descriptions[wsMgr.Get(wsid).GetIso3Code()] = descrText;
                }
            }

            if (descriptions.Count > 0)
            {
                model.SetDescription(descriptions);
            }

            AddMetsPairs(model, viProvider.ShortNumericAppVersion, cache);

            // create the dialog
            using (var dlg = new ArchivingDlg(model, "Palaso", dialogFont, new FormSettings()))
                using (var reportingAdapter = new SilErrorReportingAdapter(dlg, propertyTable))
                {
                    ErrorReport.SetErrorReporter(reportingAdapter);
                    dlg.ShowDialog(owner);
                    ErrorReport.SetErrorReporter(null);
                }

            return(true);
        }
Exemple #6
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize text of controls prior to display
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected void InitControlLabels()
 {
     try
     {
         // Set the Application label to the name of the app
         if (m_productExecutableAssembly != null)
         {
             VersionInfoProvider viProvider = new VersionInfoProvider(m_productExecutableAssembly, m_fDisplaySILInfo);
             lblProductName.Text = viProvider.ProductName;
             Text = lblProductName.Text;
             lblAppVersion.Text = viProvider.ApplicationVersion;
             lblFwVersion.Text  = viProvider.MajorVersion;
             lblCopyright.Text  = viProvider.CopyrightString + Environment.NewLine + viProvider.LicenseString;
         }
     }
     catch
     {
         // ignore errors
     }
 }
Exemple #7
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
                VersionInfoProvider viProvider = new VersionInfoProvider(ProductExecutableAssembly, true);
                lblName.Text       = viProvider.ProductName;
                lblAppVersion.Text = viProvider.ApplicationVersion;
                lblFwVersion.Text  = viProvider.MajorVersion;
                lblCopyright.Text  = viProvider.CopyrightString + Environment.NewLine + viProvider.LicenseString + Environment.NewLine + viProvider.LicenseURL;

                // 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
            }
        }
Exemple #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Backs up the project.
        /// </summary>
        /// <returns>The path to the backup file, or <c>null</c></returns>
        /// ------------------------------------------------------------------------------------
        internal string BackupProject(IThreadedProgress progressDlg)
        {
            var versionInfoProvider = new VersionInfoProvider(Assembly.GetExecutingAssembly(), false);
            var settings            = new BackupProjectSettings(m_cache, m_backupProjectView, FwDirectoryFinder.DefaultBackupDirectory,
                                                                versionInfoProvider.MajorVersion);

            settings.DestinationFolder = m_backupProjectView.DestinationFolder;

            ProjectBackupService backupService = new ProjectBackupService(m_cache, settings);
            string backupFile;

            if (!backupService.BackupProject(progressDlg, out backupFile))
            {
                var msg = string.Format(FwCoreDlgs.ksCouldNotBackupSomeFiles,
                                        string.Join(", ", backupService.FailedFiles.Select(Path.GetFileName)));
                if (MessageBox.Show(msg, FwCoreDlgs.ksWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    File.Delete(backupFile);
                }
                backupFile = null;
            }
            return(backupFile);
        }
Exemple #9
0
 protected override void BecauseOf()
 {
     VersionInfoProvider.Save(NewVersionInfo)
     .GetAwaiter().GetResult();
 }
Exemple #10
0
 protected override void BecauseOf()
 {
     VersionReadByProvider = VersionInfoProvider.Read().Result;
 }