示例#1
0
        /// <summary>
        /// This routine is heavily customized to decompress GRAMPS whole of database export file
        /// (i.e. .gramps) files.
        /// </summary>
        /// <param name="inputFile">
        /// Input GRAMPS export file.
        /// </param>
        /// <returns>
        /// Flag indicating success or not.
        /// </returns>
        public bool DecompressGZIP(IFileInfoEx inputFile)
        {
            App.Current.Services.GetService <IErrorNotifications>().DataLogEntryAdd("Decompressing GRAMPS GZIP file");

            // Check arguments
            if (inputFile == null)
            {
                App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("The input file is null"));
                return(false);
            }

            try
            {
                ExtractGZip(inputFile, "data.xml");

                App.Current.Services.GetService <IErrorNotifications>().DataLogEntryReplace("GRAMPS GZIP file decompress complete");
                return(true);
            }
            catch (UnauthorizedAccessException ex)
            {
                ErrorInfo t = new ErrorInfo("Unauthorised Access exception when trying to acess file")
                {
                    { "Exception Message ", ex.Message },
                };

                App.Current.Services.GetService <IErrorNotifications>().NotifyError(t);
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Extracts the gzip file.
        /// </summary>
        /// <param name="argInputFile">
        /// The input file.
        /// </param>
        /// <returns>
        /// </returns>
        public static bool ExtractGZip(IFileInfoEx argInputFile, string argOutFile)
        {
            if (argInputFile is null)
            {
                throw new ArgumentNullException(nameof(argInputFile));
            }

            FileStream originalFileStream = argInputFile.FInfo.OpenRead();

            byte[] dataBuffer = new byte[4096];

            GZipStream gzipStream = new GZipStream(originalFileStream, CompressionMode.Decompress);

            FileInfo fsOut = new FileInfo(Path.Combine(DataStore.Instance.AD.CurrentDataFolder.Path, argOutFile));

            FileStream fsOut1 = fsOut.Create();

            StreamUtils.Copy(gzipStream, fsOut1, dataBuffer);
            fsOut1.Flush();

            fsOut1.Dispose();
            gzipStream.Dispose();

            return(true);
        }
示例#3
0
        /// <summary>
        /// Saves the datetime the file was last modified in System Settings.
        /// </summary>
        public static void SaveLastWriteToSettings(IFileInfoEx argFileInfoEx, string argSettingsKey)
        {
            Contract.Assert(argFileInfoEx != null);

            Contract.Assert(argSettingsKey != string.Empty);

            DataStore.Instance.ES.PreferencesSet(argSettingsKey, argFileInfoEx.FInfo.LastWriteTimeUtc.ToString(System.Globalization.CultureInfo.CurrentCulture));
        }
示例#4
0
        /// <summary>
        /// Was the file modified since the last datetime saved?
        /// </summary>
        /// <returns>
        /// True if the file was modified since last time.
        /// </returns>
        public static bool ModifiedComparedToSettings(IFileInfoEx argFileInfoEx, string argSettingsKey)
        {
            Contract.Assert(argFileInfoEx != null);

            Contract.Assert(argSettingsKey != string.Empty);

            // Check for file exists
            if (!argFileInfoEx.Valid)
            {
                return(false);
            }

            try
            {
                DateTime fileDateTime = argFileInfoEx.FileGetDateTimeModified();

                // Need to reparse it so the ticks are the same
                fileDateTime = DateTime.Parse(fileDateTime.ToString(System.Globalization.CultureInfo.CurrentCulture), System.Globalization.CultureInfo.CurrentCulture);

                // Save a fresh copy if null so we can load next time
                string oldDateTime = DataStore.Instance.ES.PreferencesGet(argSettingsKey, string.Empty);

                if (string.IsNullOrEmpty(oldDateTime))
                {
                    DataStore.Instance.ES.PreferencesSet(argSettingsKey, fileDateTime.ToString(System.Globalization.CultureInfo.CurrentCulture));

                    // No previous settings entry so do the load (it might be the FirstRun)
                    return(true);
                }
                else
                {
                    DateTime settingsStoredDateTime;
                    settingsStoredDateTime = DateTime.Parse(oldDateTime, System.Globalization.CultureInfo.CurrentCulture);

                    int t = fileDateTime.CompareTo(settingsStoredDateTime);
                    if (t > 0)
                    {
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                DataStore.Instance.ES.PreferencesRemove(argSettingsKey);

                App.Current.Services.GetService <IErrorNotifications>().NotifyException("FileModifiedSinceLastSaveAsync", ex);
                throw;
            }
        }