Пример #1
0
        public override void Update(AddonMetaData addon)
        {
            string dest = Path.Combine(tempDlDir, addon.Name + ".zip");

            if (DownloadFile(addon.DownloadURL, dest, addon.Name))
                CopyUpdateToLibrary(addon.ZipName, dest);
        }
Пример #2
0
 public override void PostDelete(AddonMetaData addon)
 {
     if (Init(addon.UpdateURL))
     {
         if (Directory.Exists(info.dlPath))
         {
             ForceDeleteDirectory(info.dlPath);
         }
         if(File.Exists(info.packedFile))
         {
             File.Delete(info.packedFile);
         }
     }
 }
Пример #3
0
        public void GetMelderInstalledAddons(string path)
        {
            MainView.StatusMessage = "Discovering Installed Addons...";

            if (Directory.Exists(path))
            {
                string[] fileEntries = Directory.GetFiles(path, "*.ini");
                foreach (string fileName in fileEntries)
                {
                    using (TextReader reader = File.OpenText(fileName))
                    {
                        AddonMetaData addon = new AddonMetaData();
                        addon.ReadFromIni(reader);

                        var FullAddon = GetAddonLocalByNameAndVersion(addon.Name, addon.Version);

                        if (FullAddon != null)
                        {
                            FullAddon.IsEnabled = true;
                            FullAddon.InstalledFilesList = addon.InstalledFilesList;
                        }
                    }

                }
            }
            else
            {
                Directory.CreateDirectory(path);
            }
        }
Пример #4
0
        // Do the real updating
        public bool _UpdateAddon(AddonMetaData addon)
        {
            try
            {
                if (Statics.CheckIfFileIsReadOnly(addon.ZipName))
                {
                    App.Current.Dispatcher.Invoke((Action)delegate
                    {
                        MainWindow.ShowAlert("Addon Update Error", "The addons zip is marked as read only. Addon:  " + addon.Name);
                    });

                    return false;
                }
                if (addon.DownloadURL != null && new Version(addon.Version) < new Version(addon.AvailableVersion))
                {
                    bool isInstalled = addon.IsEnabled;
                    if (isInstalled)
                    {
                        addon.IsEnabled = false; // The observable takes care of the actions
                        AddonsToRenableAfterUpdate.Add(addon.Name);
                    }

                    addon.IsUpdating = true;
                    Providers[addon.ProviderType].Update(addon);
                    addon.IsUpdating = false;
                    //if (isInstalled)
                    //addon.IsEnabled = isInstalled;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                // MessageBox.Show(e.Message);

                App.Current.Dispatcher.Invoke((Action)delegate 
                {
                    MainWindow.ShowAlert("Addon Update Error", "There was an error updating this addon "+ addon.Name);
                });

                return false;
            }
        }
Пример #5
0
        // Add it to the list
        public void UpdateAddon(AddonMetaData addon)
        {
            lock (AddonsToUpdateLock)
            {
                AddonsToUpdate.Add(addon);
            }

            DoAddonUpdates();
        }
Пример #6
0
        public void UninstallAddon(AddonMetaData addon)
        {
            MainView.StatusMessage = string.Format("Uninstalling Addon {0}", addon.Name);

            // Addon, nice and easy
            if (addon.IsAddon)
            {
                // Remove all the installed files
                foreach (string filePath in addon.InstalledFilesList)
                {
                    string path = filePath;

                    if (path.StartsWith("Addons/")) // Melder added "Addons/" to the start when an addon was put under the my docs location so remove it
                        path = filePath.Replace("Addons/", "");

                    path = Statics.FixPathSlashes(Path.Combine(Statics.AddonsFolder, filePath));
                    if (File.Exists(path) && Statics.IsPathSafe(path))
                    {
                        File.Delete(path);
                    }
                    else if (Directory.Exists(path) && Statics.IsPathSafe(path) && Directory.GetFiles(path).Length == 0)
                    {
                        Directory.Delete(path, true);
                    }
                }

                // The info File
                string infoPath = Path.Combine(Statics.AddonsFolder, "melder_addons", Path.GetFileName(addon.ZipName)+".ini");
                if (File.Exists(infoPath) && Statics.IsPathSafe(infoPath))
                {
                    File.Delete(infoPath);
                }
            }
            else // Mods, remove and then restore backups
            {
                foreach (string filePath in addon.InstalledFilesList)
                {
                    string modFilePath = Statics.FixPathSlashes(Path.Combine(MeldiiSettings.Self.FirefallInstallPath, "system", filePath));
                    if (File.Exists(modFilePath) && Statics.IsPathSafe(modFilePath))
                    {
                        Debug.WriteLine("Uninstall, Deleting file: " + modFilePath);
                        File.Delete(modFilePath);
                    }
                    else if (Directory.Exists(modFilePath) && Statics.IsPathSafe(modFilePath) && Directory.GetFiles(modFilePath).Length == 0) // Make sure it is empty
                    {

                    }
                }

                // Restore the backup
                string backUpFilePath = Statics.GetBackupPathForMod(Path.GetFileNameWithoutExtension(addon.ZipName));

                if (File.Exists(backUpFilePath))
                {
                    ZipFile backUp = new ZipFile(backUpFilePath);
                    backUp.ExtractAll(Path.Combine(MeldiiSettings.Self.FirefallInstallPath, "system"), ExtractExistingFileAction.DoNotOverwrite);
                    backUp.Dispose();
                }

                // The info File
                string infoPath = Path.Combine(Path.Combine(MeldiiSettings.Self.FirefallInstallPath, Statics.ModDataStoreReltivePath), Path.GetFileName(addon.ZipName) + ".ini");
                if (File.Exists(infoPath) && Statics.IsPathSafe(infoPath))
                {
                    File.Delete(infoPath);
                }
            }

            MainView.StatusMessage = string.Format("Addon {0} Uninstalled", addon.Name);
        }
Пример #7
0
        // Installing and uninstalling of addon, could be neater >,>
        // Refactor plz
        public void InstallAddon(AddonMetaData addon)
        {
            // Check we have a path for the Firefall install
            if (!Statics.IsFirefallInstallValid(MeldiiSettings.Self.FirefallInstallPath))
            {
                MainWindow.ShowAlert("Error: Invalid path to Firefall install!",
                    string.Format("\"{0}\" is not a valid Firefall install\nPlease go to settings and set the path to your Firefall install",
                    MeldiiSettings.Self.FirefallInstallPath));

                return;
            }

            MainView.StatusMessage = string.Format("Installing Addon {0}", addon.Name);

            addon.InstalledFilesList.Clear();

            string dest = addon.IsAddon ? Statics.AddonsFolder : Statics.GetPathForMod(addon.Destination);
            string installInfoDest = addon.IsAddon ? Path.Combine(Statics.AddonsFolder, "melder_addons") : Path.Combine(MeldiiSettings.Self.FirefallInstallPath, Statics.ModDataStoreReltivePath);
            installInfoDest = Path.Combine(installInfoDest, Path.GetFileName(addon.ZipName) + ".ini");

            // Prep for back up
            ZipFile BackupZip = null;
            if (!addon.IsAddon)
            {
                BackupZip = new ZipFile();

                // Back up files
                foreach (string file in addon.RemoveFilesList)
                {
                    string modFilePath = Path.Combine(dest, file.ToLower().Replace(addon.Destination.ToLower(), ""));
                    if (File.Exists(modFilePath) && Statics.IsPathSafe(modFilePath))
                    {
                        Debug.WriteLine("Install, backing up file: " + modFilePath);
                        string basePath = Path.GetDirectoryName(modFilePath.Replace(Statics.GetFirefallSystemDir(), ""));
                        BackupZip.AddFile(modFilePath, basePath);
                    }
                }

                using (ZipFile zip = ZipFile.Read(addon.ZipName))
                {
                    foreach (string file in zip.EntryFileNames)
                    {
                        string modFilePath = Path.Combine(dest, file);
                        if (File.Exists(modFilePath) && Statics.IsPathSafe(modFilePath))
                        {
                            Debug.WriteLine("Install, backing up file: " + modFilePath);
                            string basePath = Path.GetDirectoryName(modFilePath.Replace(Statics.GetFirefallSystemDir(), ""));
                            BackupZip.AddFile(modFilePath, basePath);
                        }
                    }
                }

                string backuppath = Statics.GetBackupPathForMod(Path.GetFileNameWithoutExtension(addon.ZipName));

                if (File.Exists(backuppath) && Statics.IsPathSafe(backuppath))
                    File.Delete(backuppath);

                BackupZip.Save(backuppath);
                BackupZip.Dispose();

                foreach (string file in addon.RemoveFilesList)
                {
                    string modFilePath = Path.Combine(dest, file.ToLower().Replace(addon.Destination.ToLower(), ""));
                    if (File.Exists(modFilePath) && Statics.IsPathSafe(modFilePath))
                    {
                        Debug.WriteLine("Install, removing file: " + modFilePath);
                        File.Delete(modFilePath);
                    }
                }
            }

            // We go over the files one by one so that we can ingore files as we need to
            using (ZipFile zip = ZipFile.Read(addon.ZipName))
            {
                foreach (ZipEntry file in zip)
                {
                    // Extract the files to their new home
                    // Make sure its not an ignored file
                    var hits = addon.IngoreFileList.Find(x => file.FileName.ToLower().Contains(x.ToLower()));
                    if (hits == null || hits.Length == 0 && Statics.IsPathSafe(dest))
                    {
                        file.Extract(dest, ExtractExistingFileAction.OverwriteSilently);

                        string installedPath = file.FileName;

                        if (addon.Destination != null && !installedPath.Contains(addon.Destination))
                            installedPath = Path.Combine(addon.Destination, file.FileName);

                        addon.InstalledFilesList.Add(installedPath);
                    }
                }
            }

            addon.WriteToIni(installInfoDest);

            MainView.StatusMessage = string.Format("Addon {0} Installed", addon.Name);
        }
Пример #8
0
        public bool IsAddonUptoDate(AddonMetaData addon, MelderInfo melderInfo)
        {
            // There are many ways to make a bad version string :<
            addon.Version = Statics.CleanVersionString(addon.Version);
            melderInfo.Version = Statics.CleanVersionString(melderInfo.Version);


            try
            {
                Version current = new Version(addon.Version);
                Version newVer = new Version(melderInfo.Version);

                return current.CompareTo(newVer) == 0 || current.CompareTo(newVer) == 1;
            }
            catch (Exception)
            {
                return false;
            }
        }
Пример #9
0
        private void GetAddonUpdateInfo(AddonMetaData addon)
        {
            var info = Providers[addon.ProviderType].GetMelderInfo(addon.UpdateURL);
            if (addon != null && !addon.IsPendingDelete)
            {
                if (info != null)
                {
                    addon.AvailableVersion = info.Version;
                    addon.IsUptoDate = IsAddonUptoDate(addon, info);
                    addon.IsNotSuported = info.IsNotSuported;
                    addon.DownloadURL = info.Dlurl;

                    Debug.WriteLine("Addon: {0}, Version: {1}, Patch: {2}, Dlurl: {3}, IsUptodate: {4}, IsNotSuported: {5}", addon.Name, info.Version, info.Patch, info.Dlurl, addon.IsUptoDate, addon.IsNotSuported);

                    if (!addon.IsUptoDate)
                    {
                        if (!addon._IsNotSuported)
                            AddonsToBeUpdatedCount++;

                        MainView.StatusMessage = string.Format("{0} Addons need to be updated", AddonsToBeUpdatedCount);
                    }
                }
                else
                    addon.AvailableVersion = "??";
            }
        }
Пример #10
0
        public static AddonMetaData ParseZipForIni(string path)
        {
            using (ZipFile zip = ZipFile.Read(path))
            {
                foreach (ZipEntry file in zip)
                {
                    if (file.FileName.ToUpper().Contains(Properties.Settings.Default.MelderInfoName.ToUpper()))
                    {
                        TextReader reader = new StreamReader(file.OpenReader());

                        AddonMetaData addon = new AddonMetaData();
                        addon.ReadFromIni(reader);
                        return addon;
                    }
                }
            }
            return null;

        }
Пример #11
0
        public override void Update(AddonMetaData addon)
        {
            string dlurl = Properties.Settings.Default.FirefallForumsAttachURL + addon.DownloadURL;
            string dest = Path.Combine(tempDlDir, addon.Name + ".zip");

            if (DownloadFile(dlurl, dest, addon.Name))
                CopyUpdateToLibrary(addon.ZipName, dest);
        }
Пример #12
0
 public override void Update(AddonMetaData addon)
 {
     if(Init(addon.UpdateURL))
     {
         _Copy(Path.Combine(MeldiiSettings.Self.AddonLibaryPath, info.repoName) + ".zip", info.packedFile);
     }
 }