Exemplo n.º 1
0
        /// <summary>
        /// Unpacks KOM files by invoking the extractor.
        /// </summary>
        internal static void UnpackKoms()
        {
            UnpackingState = true;
            var di = new DirectoryInfo(Application.StartupPath + "\\koms");

            foreach (var fi in di.GetFiles("*.kom"))
            {
                var kom_file = fi.Name;
                var kom_ver  = GetHeaderVersion(kom_file);
                if (kom_ver != 0)
                {
                    // remove ".kom" on end of string.
                    var kom_data_folder = Path.GetFileNameWithoutExtension(Application.StartupPath + "\\koms\\" + kom_file);
                    foreach (var komplugin in KOMStream.Komplugins)
                    {
                        try
                        {
                            if (kom_ver == komplugin.SupportedKOMVersion)
                            {
                                komplugin.Unpack(Application.StartupPath + "\\koms\\" + kom_file, Application.StartupPath + "\\koms\\" + kom_data_folder, kom_file);
                            }
                            else
                            {
                                // loop until the right plugin for this kom version is found.
                                continue;
                            }

                            // make the version dummy file for the packer.
                            try
                            {
                                using (File.Create(Application.StartupPath + "\\koms\\" + kom_data_folder + "\\KOMVERSION." + kom_ver))
                                {
                                }
                            }
                            catch (DirectoryNotFoundException)
                            {
                                // cannot create this since nothing was written or made.
                            }

                            // delete original kom file.
                            komplugin.Delete(Application.StartupPath + "\\koms\\" + kom_file, false);
                        }
                        catch (NotUnpackableException)
                        {
                            // do not delete kom file.
                            MessageManager.ShowError("Unpacking this KOM file failed.", "Error!", Convert.ToBoolean(Convert.ToInt32(SettingsFile.Settingsxml?.TryRead("UseNotifications") != string.Empty ? SettingsFile.Settingsxml?.TryRead("UseNotifications") : "0")));
                        }
                        catch (NotImplementedException)
                        {
                            MessageManager.ShowError("The KOM V" + komplugin.SupportedKOMVersion + " plugin does not implement an unpacker function yet. Although it should.", "Error!", Convert.ToBoolean(Convert.ToInt32(SettingsFile.Settingsxml?.TryRead("UseNotifications") != string.Empty ? SettingsFile.Settingsxml?.TryRead("UseNotifications") : "0")));
                        }
                    }
                }
                else
                {
                    MessageManager.ShowError("Unknown KOM version Detected. Please send this KOM to the Els_kom Developers file for inspection.", "Error!", Convert.ToBoolean(Convert.ToInt32(SettingsFile.Settingsxml?.TryRead("UseNotifications") != string.Empty ? SettingsFile.Settingsxml?.TryRead("UseNotifications") : "0")));
                }
            }

            UnpackingState = false;
        }