Пример #1
0
        private static void DetectMyMods(List <TroveMod> myMods)
        {
            try
            {
                log.Info("Detecting My Mods");
                string        modsFolder = SettingsDataProvider.ModsFolder;
                List <string> modFiles   = new List <string>(Directory.GetFiles(modsFolder, ZipFileTypeSearchPattern));
                modFiles.AddRange(Directory.GetFiles(modsFolder, TmodFileTypeSearchPattern));

                string toolboxMods = SettingsDataProvider.TroveToolboxModsFolder;
                if (toolboxMods != null)
                {
                    modFiles.AddRange(Directory.GetFiles(toolboxMods, ZipFileTypeSearchPattern));
                    modFiles.AddRange(Directory.GetFiles(toolboxMods, TmodFileTypeSearchPattern));
                }

                foreach (string modFile in modFiles)
                {
                    // Add the mod if there are no other mods with this file name already
                    if (!myMods.Any(m => Path.GetFileName(m.FilePath).Equals(Path.GetFileName(modFile), StringComparison.OrdinalIgnoreCase)))
                    {
                        TroveMod mod = new TroveMod(modFile);
                        mod.AddMod();
                        mod.InstallMod();
                        myMods.Add(mod);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Warn("Error detecting my mods", ex);
            }
        }
Пример #2
0
        public static string DownloadMod(TroveMod mod, string fileId)
        {
            if (mod?.Id == null)
            {
                throw new ArgumentNullException("mod.Id");
            }
            if (mod?.Downloads == null)
            {
                throw new ArgumentNullException("mod.Downloads");
            }

            var    download  = mod.Downloads.First(m => m.FileId == fileId);
            string unixDate  = download.Date;
            string fileName  = string.Format("{0}+{1}.{2}", TroveMod.FilterModFilename(mod.Name), unixDate, string.IsNullOrEmpty(download.Format) ? "zip" : download.Format);
            string localPath = Path.Combine(SettingsDataProvider.ModsFolder, fileName);

            using (var client = OpenWebClient())
            {
                string url = AddQuerystring(string.Format(ModDownloadUrl, mod.Id, fileId));
                client.DownloadFile(url, localPath);
            }
            mod.CurrentFileId = fileId;
            try { mod.UnixTimeSeconds = Convert.ToInt64(unixDate); } catch { }

            return(localPath);
        }
Пример #3
0
        public static string DownloadMod(TroveMod mod)
        {
            if (mod?.Id == null)
            {
                throw new ArgumentNullException("mod.Id");
            }
            if (mod?.Downloads == null)
            {
                throw new ArgumentNullException("mod.Downloads");
            }

            return(DownloadMod(mod, mod.LatestDownload.FileId));
        }
Пример #4
0
 public static TroveMod GetMod(string id, string name = "")
 {
     try
     {
         var ic  = StringComparison.OrdinalIgnoreCase;
         var mod = ModList.FirstOrDefault(m => m.Id.Equals(id, ic));
         if (mod == null)
         {
             mod = ModList.FirstOrDefault(m => TroveMod.FilterModFilename(m.Name).Equals(TroveMod.FilterModFilename(name), ic));
         }
         return(mod);
     }
     catch (Exception ex) { log.ErrorFormat("Error retrieving matching mod from Trovesaurus for mod {0}: {1}", string.IsNullOrEmpty(name) ? "id " + id : name, ex.Message); }
     return(null);
 }
Пример #5
0
        public TroveMod(string filePath)
        {
            log.InfoFormat("Loading mod from file: {0}", filePath);
            FilePath = filePath;

            Match filenameMatch = Regex.Match(Path.GetFileNameWithoutExtension(filePath), @"^(?<Name>.*?)(?:\+(?<UnixTimeSeconds>\d+))?$");

            if (filenameMatch.Success)
            {
                Name = filenameMatch.Groups["Name"].Value;
            }
            else
            {
                Name = Path.GetFileNameWithoutExtension(filePath);
            }

            if (filenameMatch.Success && !string.IsNullOrEmpty(filenameMatch.Groups["UnixTimeSeconds"]?.Value))
            {
                UnixTimeSeconds = Convert.ToInt64(filenameMatch.Groups["UnixTimeSeconds"].Value);
            }
            else
            {
                UnixTimeSeconds = new DateTimeOffset(new FileInfo(filePath).LastWriteTime).ToUnixTimeSeconds();
            }

            if (TmodFormat)
            {
                // Load properties set in the Tmod file
                Name = ModTitle;
                if (TmodProperties.ContainsKey(TModFormat.AuthorValue))
                {
                    Author = TmodProperties[TModFormat.AuthorValue];
                }
                if (TmodProperties.ContainsKey(TModFormat.NotesValue))
                {
                    Description = TmodProperties[TModFormat.NotesValue];
                }
            }

            // Attempt to find matching mod from Trovesaurus API and load additional data
            TroveMod mod = FindTrovesaurusMod();

            UpdatePropertiesFromTrovesaurus(mod);
        }
Пример #6
0
        public void CheckForUpdates()
        {
            try
            {
                log.DebugFormat("Checking for updates for mod: {0}", Name);
                bool updatesAvailable = false;

                // Verify mod file exists
                if (!File.Exists(FilePath))
                {
                    log.ErrorFormat("File [{0}] not found for mod {1}", FilePath, Name);
                    Status  = string.Format(Strings.TroveMod_Status_Error, "File not found");
                    Enabled = false;
                    return;
                }

                // Check for updates
                TroveMod mod = FindTrovesaurusMod();
                if (mod != null)
                {
                    if (Convert.ToInt64(mod.LatestDownload.Date) > UnixTimeSeconds)
                    {
                        updatesAvailable = true;
                    }
                    UpdatePropertiesFromTrovesaurus(mod);
                }

                if (updatesAvailable)
                {
                    Status = Strings.TroveMod_Status_NewVersionAvailable;
                }
                else
                {
                    Status = Strings.TroveMod_Status_UpToDate;
                }
            }
            catch (Exception ex)
            {
                log.Error("Error checking for updates for mod: " + Name, ex);
                Status = string.Format(Strings.TroveMod_Status_Error, ex.Message);
            }
        }
Пример #7
0
        public void UpdatePropertiesFromTrovesaurus(TroveMod mod)
        {
            if (mod != null)
            {
                Id   = mod.Id;
                Name = mod.Name;
                if (!string.IsNullOrWhiteSpace(mod.Author))
                {
                    Author = mod.Author;
                }
                Type    = mod.Type;
                SubType = mod.SubType;
                if (!string.IsNullOrWhiteSpace(mod.Description))
                {
                    Description = mod.Description;
                }
                DateCreated       = mod.DateCreated;
                TrovesaurusStatus = mod.TrovesaurusStatus;
                Replaces          = mod.Replaces;
                TotalDownloads    = mod.TotalDownloads;
                Votes             = mod.Votes;
                Views             = mod.Views;
                Downloads         = new List <Download>(mod.Downloads);
                ImagePath         = mod.ImagePath;
                ImageFullPath     = mod.ImageFullPath;

                // Get the current file ID using the file date if it is not already set
                if (string.IsNullOrEmpty(CurrentFileId))
                {
                    var download = Downloads.FirstOrDefault(d => d.Date == UnixTimeSeconds.ToString());
                    if (download != null)
                    {
                        CurrentFileId = download.FileId;
                    }
                }
            }
        }