Ejemplo n.º 1
0
        public static DatabaseFin FullyLoadFin(DatabaseFin fin)
        {
            DatabaseFin finCopy = new DatabaseFin(fin);

            // TODO: Cache images?
            if (!string.IsNullOrEmpty(finCopy.ImageFilename))
            {
                CatalogSupport.UpdateFinFieldsFromImage(Options.CurrentUserOptions.CurrentSurveyAreaPath, finCopy);

                string fullImageFilename = Path.Combine(Options.CurrentUserOptions.CurrentSurveyAreaPath,
                                                        (string.IsNullOrEmpty(finCopy.OriginalImageFilename)) ? finCopy.ImageFilename : finCopy.OriginalImageFilename);

                if (File.Exists(fullImageFilename))
                {
                    var img = System.Drawing.Image.FromFile(fullImageFilename);

                    var bitmap = new Bitmap(img);
                    // TODO: Hack for HiDPI -- this should be more intelligent.
                    bitmap.SetResolution(96, 96);

                    finCopy.OriginalFinImage = new Bitmap(bitmap);

                    // TODO: Refactor this so we're not doing it every time, which is a little crazy
                    if (finCopy.ImageMods != null && finCopy.ImageMods.Count > 0)
                    {
                        bitmap = ModificationHelper.ApplyImageModificationsToOriginal(bitmap, finCopy.ImageMods);
                        // TODO: HiDPI hack
                        bitmap.SetResolution(96, 96);
                    }

                    finCopy.FinImage = bitmap;
                }
            }

            if (!string.IsNullOrEmpty(finCopy.OriginalImageFilename) && !File.Exists(finCopy.OriginalImageFilename))
            {
                finCopy.OriginalImageFilename = Path.Combine(Options.CurrentUserOptions.CurrentSurveyAreaPath, finCopy.OriginalImageFilename);
            }

            return(finCopy);
        }
Ejemplo n.º 2
0
        public static string RestoreDatabase(string backupFile, string surveyArea, string databaseName)
        {
            var fullDatabaseName = CatalogSupport.CalculateDatabaseFilename(Options.CurrentUserOptions.CurrentDarwinHome, databaseName, surveyArea);

            RebuildFolders(fullDatabaseName);

            using (var fs = new FileStream(backupFile, FileMode.Open, FileAccess.Read))
            {
                using (var zipArchive = new ZipArchive(fs, ZipArchiveMode.Read))
                {
                    string destinationDirectory = new FileInfo(fullDatabaseName).Directory.FullName;

                    // We need to loop through the entries, as we want to be able to overwrite the destination
                    // files.  There's no option to do that with ExtractToDirectory
                    foreach (var entry in zipArchive.Entries)
                    {
                        entry.ExtractToFile(Path.Combine(destinationDirectory, entry.FullName), true);
                    }
                }
            }

            return(fullDatabaseName);
        }