public string DownloadImage(string folder)
        {
            string previewPath = null;

            if (ImageFullPath != null && !ImageFullPath.EndsWith("modconstruction.jpg"))
            {
                try
                {
                    previewPath = Path.Combine(folder, string.Format("{0}{1}", SettingsDataProvider.GetSafeFilename(Name), Path.GetExtension(ImageFullPath)));
                    TrovesaurusApi.DownloadFile(ImageFullPath, previewPath);
                }
                catch (Exception ex)
                {
                    log.Warn(string.Format("Error downloading image {0}, retrying with new filename", Path.GetFileName(previewPath)), ex);
                    int i = 1;
                    while (File.Exists(previewPath))
                    {
                        previewPath = Path.Combine(folder, string.Format("{0} {1}{2}", SettingsDataProvider.GetSafeFilename(Name), i++, Path.GetExtension(ImageFullPath)));
                    }
                    try { TrovesaurusApi.DownloadFile(ImageFullPath, previewPath); }
                    catch (Exception e)
                    {
                        log.Error(string.Format("Error downloading image {0}", Path.GetFileName(previewPath)), e);
                        previewPath = null;
                    }
                }
            }
            return(previewPath);
        }
Exemple #2
0
 public static void StopTimer()
 {
     log.InfoFormat("Stopping Trove game status checking");
     try
     {
         _UpdateTroveGameStatusTimer?.Stop();
         TrovesaurusApi.UpdateTroveGameStatus(false);
     }
     catch (Exception ex) { log.Error("Error stopping Trove game status detection", ex); }
 }
        public static TroveMod GetMod(string id)
        {
            var mod = MyMods.FirstOrDefault(m => m.Id == id);

            if (mod != null)
            {
                return(mod);
            }

            mod = TrovesaurusApi.GetMod(id);
            return(mod);
        }
Exemple #4
0
 private static void _UpdateTroveGameStatusTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         bool isTroveRunning = false;
         foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(TroveLocation.TroveExecutableFileName)))
         {
             try
             {
                 string cmdLine = process.GetCommandLine();
                 if (!cmdLine.Contains("tool"))
                 {
                     isTroveRunning = true;
                     break;
                 }
             }
             // Catch and ignore "access denied" exceptions.
             catch (Win32Exception ex) when(ex.HResult == -2147467259)
             {
             }
             // Catch and ignore "Cannot process request because the process (<pid>) has exited." exceptions.
             catch (InvalidOperationException ex) when(ex.HResult == -2146233079)
             {
             }
         }
         if (isTroveRunning)
         {
             if (!_Online.HasValue || _Online.Value == false)
             {
                 _Online = true;
                 string status = TrovesaurusApi.UpdateTroveGameStatus(_Online.Value);
                 log.InfoFormat("Trove game detected running, updated Trovesaurus game status (return value: {0})", status);
             }
         }
         else
         {
             if (!_Online.HasValue || _Online.Value == true)
             {
                 _Online = false;
                 string status = TrovesaurusApi.UpdateTroveGameStatus(_Online.Value);
                 log.InfoFormat("Trove game detected not running, updated Trovesaurus game status (return value: {0})", status);
             }
         }
     }
     catch (Exception ex) { log.Error("Error in Trove game status detection", ex); }
 }
        public void UpdateMod(string fileId)
        {
            try
            {
                // Uninstall existing mod prior to installing new version
                string oldFile = FilePath;
                if (Enabled && !string.IsNullOrEmpty(oldFile) && File.Exists(oldFile))
                {
                    UninstallMod(true);
                }

                log.InfoFormat("Downloading mod: {0} with download file ID {1}", Name, fileId);
                Status   = Strings.TroveMod_Status_Downloading;
                FilePath = TrovesaurusApi.DownloadMod(this, fileId);

                if (!string.IsNullOrEmpty(oldFile) && FilePath != oldFile && File.Exists(oldFile))
                {
                    try { File.Delete(oldFile); }
                    catch (Exception ex) { log.Warn("Error removing previous file: " + oldFile, ex); }
                }

                if (Enabled)
                {
                    InstallMod();
                }
                else
                {
                    CheckForUpdates();
                }
            }
            catch (Exception ex)
            {
                log.Error("Error downloading mod: " + Name, ex);
                Status = string.Format(Strings.TroveMod_Status_Error, ex.Message);
            }
        }
 private TroveMod FindTrovesaurusMod()
 {
     return(TrovesaurusApi.GetMod(Id, Name));
 }