/// <summary> /// Calls a MapPackageAction in a safe environment by catching all the exceptions /// and translating them to appropiate responsecodes. /// </summary> /// <param name="Action">A MapPackageAction which updates the osz2 file in the save environment</param> /// <param name="MappackageFile">Path to the osz2 fileparam> /// <param name="Key">The key used to decrypt or encrypt the mappackage</param> /// <param name="SaveData">Whether to save the data after using the custom defined action on the beatmap</param> /// <returns>the UpdateResponseCode of the custom defined action when no exception has occured /// while loading the beatmap(osz2) file, or a failed UpdateResponseCode when there has.</returns> private UpdateResponseCode DoMapPackageActionSafe(MapPackageAction Action, string MappackageFile, byte[] Key, bool SaveData, bool MetadataOnly) { string originalPath = MappackageFile; if (!File.Exists(MappackageFile)) { MappackageFile = s3getToTemp("osz2/" + MappackageFile); } else { originalPath = Path.GetFileName(originalPath); } UpdateResponseCode CustomResponseCode; if (!File.Exists(MappackageFile)) { return(UpdateResponseCode.FileDoesNotExist); } try { using (MapPackage Osz2Beatmap = new MapPackage(MappackageFile, Key, false, MetadataOnly)) { CustomResponseCode = Action(Osz2Beatmap); if (CustomResponseCode == UpdateResponseCode.UpdateSuccessful && SaveData) { Osz2Beatmap.Save(); } Osz2Beatmap.Close(); } if (CustomResponseCode == UpdateResponseCode.UpdateSuccessful && SaveData) { s3putFile("osz2/" + originalPath, MappackageFile); } } catch (IOException e) { log(e); return(UpdateResponseCode.Osz2Corrupted); } catch (Exception e) { log(e); return(UpdateResponseCode.UnknownError); } finally { } return(CustomResponseCode); }
/// <summary> /// Calls a MapPackageAction in a safe environment by catching all the exceptions /// and translating them to appropiate responsecodes. /// </summary> /// <param name="Action">A MapPackageAction which updates the osz2 file in the save environment</param> /// <param name="BeatmapSetID">The filename of the osz2 package.</param> /// <param name="Key">The key used to decrypt or encrypt the mappackage</param> /// <param name="SaveData">Whether to save the data after using the custom defined action on the beatmap</param> /// <returns>the UpdateResponseCode of the custom defined action when no exception has occured /// while loading the beatmap(osz2) file, or a failed UpdateResponseCode when there has.</returns> private UpdateResponseCode DoMapPackageActionSafe(MapPackageAction Action, int BeatmapSetID, byte[] Key, bool SaveData, bool MetadataOnly) { return(DoMapPackageActionSafe(Action, BeatmapSetID + ".osz2", Key, SaveData, MetadataOnly)); }