private static AIRVersionData ReturnUsingMetadata(string destination, AIR_API.VersionMetadata meta)
            {
                var data = new AIRVersionData(meta.Version, meta.VersionString, meta);

                DataRefrence.Add(destination, data);
                return(data);
            }
            private static AIR_API.VersionMetadata CheckforMetadataFile(string destination)
            {
                if (destination == null || destination == "" || !Directory.Exists(destination))
                {
                    return(null);
                }
                string metaDataFile = Directory.GetFiles(destination, "metadata.json", SearchOption.AllDirectories).FirstOrDefault();

                if (metaDataFile != null && metaDataFile != "")
                {
                    try
                    {
                        AIR_API.VersionMetadata ver = new AIR_API.VersionMetadata(new FileInfo(metaDataFile));
                        return(ver);
                    }
                    catch
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
Example #3
0
        public static void UpdateAIRVersionsForPlaybackToolstrips(ref ModManager Instance)
        {
            Management.RecordingManagement.UpdateGameRecordingManagerButtons(ref Instance);
            CleanUpInstalledVersionsForPlaybackToolStrip(ref Instance);
            Instance.PlayUsingOtherVersionMenuItem.IsEnabled      = false;
            Instance.PlayUsingOtherVersionHoverMenuItem.IsEnabled = false;
            if (Directory.Exists(Management.ProgramPaths.Sonic3AIR_MM_VersionsFolder))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(Management.ProgramPaths.Sonic3AIR_MM_VersionsFolder);
                var           folders       = directoryInfo.GetDirectories().ToList();
                if (folders.Count != 0)
                {
                    foreach (var folder in folders.VersionSort().Reverse())
                    {
                        string filePath = Path.Combine(folder.FullName, "sonic3air_game", "Sonic3AIR.exe");
                        if (File.Exists(filePath))
                        {
                            Instance.PlayUsingOtherVersionMenuItem.Items.Add(GenerateInstalledVersionsForPlaybackToolstripItem(folder.Name, filePath, ref Instance));
                            Instance.PlayUsingOtherVersionHoverMenuItem.Items.Add(GenerateInstalledVersionsForPlaybackToolstripItem(folder.Name, filePath, ref Instance));
                            string versionID = folder.Name;
                            if (File.Exists(Path.Combine(folder.FullName, "sonic3air_game", "data", "metadata.json")))
                            {
                                AIR_API.VersionMetadata meta = new AIR_API.VersionMetadata(new FileInfo(Path.Combine(folder.FullName, "sonic3air_game", "data", "metadata.json")));
                                versionID = meta.VersionString;

                                Instance.PlayUsingOtherVersionMenuItem.IsEnabled      = true;
                                Instance.PlayUsingOtherVersionHoverMenuItem.IsEnabled = true;
                            }
                            RecordingVersions.Add(versionID, filePath);
                        }
                    }
                }
            }
        }
 public static AIRVersionData GetVersionData(string destination, bool isAdding = false)
 {
     if (DataRefrence.ContainsKey(destination))
     {
         return(DataRefrence[destination]);
     }
     else
     {
         AIR_API.VersionMetadata VersionData = CheckforMetadataFile(destination);
         if (VersionData == null)
         {
             return(GetDataFromEXE(destination, isAdding));
         }
         else
         {
             return(ReturnUsingMetadata(destination, VersionData));
         }
     }
 }
Example #5
0
        private int CheckFromSelectedVersion(Version comparision)
        {
            string path = (Management.ProgramPaths.Sonic3AIRPath != null && Management.ProgramPaths.Sonic3AIRPath != "" ? Path.GetDirectoryName(Management.ProgramPaths.Sonic3AIRPath) : "");

            if (path == "" || !Directory.Exists(path))
            {
                return(0);
            }
            else
            {
                string metaDataFile = Directory.GetFiles(path, "metadata.json", SearchOption.AllDirectories).FirstOrDefault();
                if (metaDataFile != null)
                {
                    try
                    {
                        var metadata = new AIR_API.VersionMetadata(new FileInfo(metaDataFile));
                        return(metadata.Version.CompareTo(comparision));
                    }
                    catch
                    {
                        return(0);
                    }
                }
                else
                {
                    string exe             = Directory.GetFiles(path, "Sonic3AIR.exe", SearchOption.AllDirectories).FirstOrDefault();
                    var    versInfo        = FileVersionInfo.GetVersionInfo(exe);
                    string fileVersionFull = $"{versInfo.FileMajorPart}.{versInfo.FileMinorPart}.{versInfo.FileBuildPart}.{versInfo.FilePrivatePart}";
                    if (Version.TryParse(fileVersionFull, out Version result))
                    {
                        return(result.CompareTo(comparision));
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
        }
 public AIRVersionData(Version _ver, string _ver_string, AIR_API.VersionMetadata _meta)
 {
     Version       = _ver;
     VersionString = _ver_string;
     Metadata      = _meta;
 }
Example #7
0
        private void UpdateDownloadComplete()
        {
            string destination = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Sonic3AIR_MM\\downloads";
            string file        = $"{destination}\\{UpdateFileName}";
            string output      = destination;

            using (var archive = SharpCompress.Archives.Zip.ZipArchive.Open(file))
            {
                foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
                {
                    entry.WriteToDirectory(output, new ExtractionOptions()
                    {
                        ExtractFullPath = true,
                        Overwrite       = true
                    });
                }
            }

            try
            {
                string metaDataFile = Directory.GetFiles(output, "metadata.json", SearchOption.AllDirectories).FirstOrDefault();
                string version      = "";

                if (File.Exists(metaDataFile))
                {
                    FileInfo fileInfo           = new FileInfo(metaDataFile);
                    AIR_API.VersionMetadata ver = new AIR_API.VersionMetadata(fileInfo);
                    version = ver.VersionString;
                }
                else
                {
                    string exe             = Directory.GetFiles(output, "Sonic3AIR.exe", SearchOption.AllDirectories).FirstOrDefault();
                    var    versInfo        = FileVersionInfo.GetVersionInfo(exe);
                    string fileVersionFull = $"{versInfo.FileMajorPart}.{versInfo.FileMinorPart}.{versInfo.FileBuildPart}.{versInfo.FilePrivatePart}";
                    if (Version.TryParse(fileVersionFull, out Version result))
                    {
                        version = result.ToString();
                    }
                    else
                    {
                        //TODO: Improve Exception Handling
                        var exception = new Exception("Unable to Prase Version");
                        MessageBox.Show(Program.LanguageResource.GetString("UpdateFailedError") + Environment.NewLine, exception.Message);
                        Program.AIRUpdaterState = Program.UpdateState.Finished;
                        Close();
                    }
                }


                //TODO : Add Proper Download Cache for Failed Install of Downloads

                string output2 = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\Sonic3AIR_MM\\air_versions\\{version}\\sonic3air_game";

                if (Directory.Exists(output2))
                {
                    // TODO : Add Collision Handling
                    Directory.Delete(output2, true);
                }
                string download_source = Path.Combine(destination, "sonic3air_game");
                Microsoft.VisualBasic.FileIO.FileSystem.MoveDirectory(download_source, output2, true);

                MessageBox.Show($"{Program.LanguageResource.GetString("GameInstalledAt")} \"{output2}\"");

                Program.AIRUpdaterState = Program.UpdateState.Finished;
                try { Management.FileManagement.WipeFolderContents(Management.ProgramPaths.Sonic3AIR_MM_DownloadsFolder); }
                catch (Exception ex) { }
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Program.LanguageResource.GetString("UpdateFailedError") + Environment.NewLine, ex.Message);
                Program.AIRUpdaterState = Program.UpdateState.Finished;
                Close();
            }
        }