Exemplo n.º 1
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 = "??";
                }
            }
        }
Exemplo n.º 2
0
        public static AddonMetaData ParseZipForIni(string path)
        {
            try
            {
                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);

                            Debug.WriteLine("addon.Destination: " + addon.Destination);

                            return addon;
                        }
                    }
                }
            }
            catch (ZipException)
            { }

            return null;
        }
Exemplo n.º 3
0
        private void WatcherAdd(object source, FileSystemEventArgs e)
        {
            // Yo block untill its not in use!
            while (Statics.IsFileLocked(new FileInfo(e.FullPath)))
            {
                Thread.Sleep(500);
            }

            AddonMetaData addon = ParseZipForIni(e.FullPath);

            if (addon != null)
            {
                addon.ZipName = e.FullPath;
                addon.CheckIfAddonOrMod(); // Important or else it will think it is a mod and will install to Firefall/system

                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    MainView.LocalAddons.Add(addon);
                });

                // Should we reenable this addon?
                if (AddonsToRenableAfterUpdate.Contains(addon.Name))
                {
                    addon.IsEnabled = true;
                    AddonsToRenableAfterUpdate.Remove(addon.Name);
                }

                MainView.SortAddonList();
                GetAddonUpdateInfo(addon);
            }
        }
Exemplo n.º 4
0
 public override void Update(AddonMetaData addon)
 {
     if (Init(addon.UpdateURL))
     {
         _Copy(Path.Combine(MeldiiSettings.Self.AddonLibaryPath, info.repoName) + ".zip", info.packedFile);
     }
 }
Exemplo n.º 5
0
        private void WatcherRemove(object source, FileSystemEventArgs e)
        {
            AddonMetaData addon = null;

            if (MainView.LocalAddons != null && MainView.LocalAddons.Count != 0)
            {
                addon = MainView.LocalAddons.FirstOrDefault(x => x.ZipName == e.FullPath);

                if (addon != null)
                {
                    addon.IsPendingDelete = true;

                    // wpf oh you be crazy sometime with execptions
                    App.Current.Dispatcher.BeginInvoke((Action) delegate
                    {
                        if (MainView.LocalAddons.Contains(addon))
                        {
                            int idx = MainView.LocalAddons.IndexOf(addon);
                            if (idx != -1 && idx < MainView.LocalAddons.Count)
                            {
                                addon = null;
                                addon = MainView.LocalAddons[idx];
                                addon = null;
                                MainView.LocalAddons.RemoveAt(idx);
                            }
                        }
                    });
                }
            }
        }
Exemplo n.º 6
0
        // Genrate a list of addons that we have locally
        public void GetLocalAddons()
        {
            MainView.StatusMessage = "Discovering Addon libary";

            MainView.LocalAddons.Clear();

            string path = MeldiiSettings.Self.AddonLibaryPath;

            if (Directory.Exists(path))
            {
                string[] fileEntries = Directory.GetFiles(path, "*.zip");
                foreach (string fileName in fileEntries)
                {
                    AddonMetaData addon = ParseZipForIni(fileName);
                    if (addon != null)
                    {
                        addon.ZipName = fileName;
                        addon.CheckIfAddonOrMod();
                        MainView.LocalAddons.Add(addon);
                    }
                }
            }
            else
            {
                Directory.CreateDirectory(path);
            }
        }
Exemplo n.º 7
0
        public async void DeleteAddonFromLibrary(int SelectedAddonIndex)
        {
            AddonMetaData addon = MainView.LocalAddons[SelectedAddonIndex];

            if (addon != null)
            {
                if (addon.IsEnabled)
                {
                    bool result = await MainWindow.ShowMessageDialogYesNo("Do you want to uninstall this addon?", string.Format("The addon has been removed from the library but is still installed\n Select yes to uninstall the addon or no to keep it installed", addon.Name));

                    if (result)
                    {
                        UninstallAddon(addon);
                    }
                }

                if (File.Exists(addon.ZipName) && !Statics.CheckIfFileIsReadOnly(addon.ZipName))
                {
                    MainView.StatusMessage = string.Format("Removed {0} Ver. {1} from the addon library", addon.Name, addon.Version);
                    File.Delete(addon.ZipName);
                    Providers[addon.ProviderType].PostDelete(addon); // cleaning up git repos
                    // Let the file watcher take care of updating the list?
                }
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        // Add it to the list
        public void UpdateAddon(AddonMetaData addon)
        {
            lock (AddonsToUpdateLock)
            {
                AddonsToUpdate.Add(addon);
            }

            DoAddonUpdates();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 12
0
        public AddonMetaData GetAddonLocalByNameAndVersion(string name, string version)
        {
            AddonMetaData addon = null;

            if (MainView.LocalAddons != null && MainView.LocalAddons.Count != 0)
            {
                addon = MainView.LocalAddons.FirstOrDefault(x => x.Name == name && x.Version == version);
            }

            return(addon);
        }
Exemplo n.º 13
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);
         }
     }
 }
Exemplo n.º 14
0
        private void WatcherAdd(object source, FileSystemEventArgs e)
        {
            var retires = 3;

            // Yo block untill its not in use! 
            while (Statics.IsFileLocked(new FileInfo(e.FullPath)))
            {
                Thread.Sleep(500);
            }

            while (retires > 0)
            {
                try
                {
                    AddonMetaData addon = ParseZipForIni(e.FullPath);
                    if (addon != null)
                    {
                        addon.ZipName = e.FullPath;
                        addon.CheckIfAddonOrMod(); // Important or else it will think it is a mod and will install to Firefall/system

                        App.Current.Dispatcher.Invoke((Action)delegate
                        {
                            MainView.LocalAddons.Add(addon);
                        });

                        // Should we reenable this addon?
                        if (AddonsToRenableAfterUpdate.Contains(addon.Name))
                        {
                            addon.IsEnabled = true;
                            AddonsToRenableAfterUpdate.Remove(addon.Name);
                        }

                        MainView.SortAddonList();
                        GetAddonUpdateInfo(addon);
                        return;
                    }
                }
                catch (IOException)
                {
                    retires--;
                }
            }

            App.Current.Dispatcher.Invoke((Action)delegate
            {
                MainWindow.ShowAlert("Error", string.Format("Failed to open file {0}", e.FullPath));
            });
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
0
 public override MelderInfo GetMelderInfo(string url)
 {
     if (Init(url))
     {
         DownloadAddon();
         AddonMetaData meta = AddonManager.ParseZipForIni(info.packedFile);
         if (meta != null)
         {
             MelderInfo mInfo = new MelderInfo();
             mInfo.IsNotSuported = !IsSupported();
             mInfo.Version       = meta.Version;
             mInfo.Patch         = meta.Patch;
             mInfo.ProviderType  = meta.ProviderType;
             mInfo.Dlurl         = url;
             return(mInfo);
         }
     }
     return(null);
 }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
 public virtual void PostDelete(AddonMetaData addon)
 {
 }
Exemplo n.º 20
0
 public virtual void Update(AddonMetaData addon)
 {
 }
Exemplo n.º 21
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;

                        Debug.WriteLine("addon.Destination: " + addon.Destination);

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

                        Debug.WriteLine("installedPath: " + installedPath);

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

            addon.WriteToIni(installInfoDest);

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