Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/19 14:38:47 (6 years ago)
Author:
jkarder
Message:

#2520: changed deserialization in PersistenceContentManager

  • added method to check if old persistence can open a file
  • used this method to determine which persistence to use
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs

    r16565 r16945  
    288288      }
    289289    }
     290
     291    /// <summary>
     292    /// Checks if the given file can be opened as <see cref="ZipArchive" />.
     293    /// </summary>
     294    /// <param name="filename">The filename.</param>
     295    /// <returns><see langword="true" /> if the file can be opened as <see cref="ZipArchive" />; otherwise, <see langword="false" />.</returns>
     296    public static bool CanOpen(string filename) {
     297      try {
     298        using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
     299          using (ZipArchive zip = new ZipArchive(fs)) {
     300            return true;
     301          }
     302        }
     303      } catch (InvalidDataException) {
     304        return false;
     305      }
     306    }
    290307  }
    291308}
Note: See TracChangeset for help on using the changeset viewer.