Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Would someone mind sharing their update check code?

Featured Replies

Would someone mind sharing their update check code?

As I saw albo1125's update code and it looks real nice it is just I couldn't find any function inside the LSPDFR API class to do the update checking with(as I thought it was apart of the LSPDFR api now).

As I read awhile back cyan was going to implement this so you could just use your listing here on lcpdfr.com and use json or something to return the latest version and tell the person that there is a update available although I am unable to find that at this time....so would someone else mind helping me out?

My plugins by me are on this site in addition to my own site as well.

Do Not PM Me for Support! follow the instructions for getting support with any mods. 

Cyan did indeed post it:

On 11/21/2015 at 10:42 AM, Cyan said:

-SNIP-

You can now query the following URL:

http://www.lcpdfr.com/applications/downloadsng/interface/api.php?do=checkForUpdates&fileId=8082
And it will return a JSON object with version and pageUrl. Version will equal to the current version of the file, exactly as specified in the file manager. pageUrl will equal the URL to the file's page on LCPDFR.com.
If you just want a text string with the latest version, you can call the following URL instead:
http://www.lcpdfr.com/applications/downloadsng/interface/api.php?do=checkForUpdates&fileId=8082&textOnly=1
Note that there may be up to a 30 minute delay between updating the file and the above showing the new version, due to caching.

If anyone else wants to use this, you just have to change the fileId to the ID of the file. You can determine your file ID by the URL of your file. e.g.:
http://www.lcpdfr.com/files/file/8082-code-3-callouts/
The file ID in this case would be 8082.

 

 

Wenn ich Deutsch sprechen, enschultigung: Mein Deutsch ist nicht sehr gut.

gATXSNG.png

 If you are replying to something I have posted, you may wish to quote me for faster response times; I do not usually follow threads I reply to.
My personal inbox is not the support forum. I don't mind helping  you with your issues, but you are responsible for your research.  I am not a page in a manual, Google, or the forum search function - look through all three before asking.
A link to a handy how-to guide for getting useful solutions to your problems, and useful answers to your questions. A lot of it may seem irrelevant, but it outlines some great practices to use when seeking answers or solutions.

I use this in my Main.cs, and then call it during OnOnDutyStateChanged.

It uses an .ini file to store the preference for whether automatic update checking is enabled, and when the last update check is done. As below, it won't check for updates more frequently than once per day and waits a random interval between 7.5 and 45 seconds before trying to do the check.

This isn't in the released version of my plugin yet, and it's only been lightly tested, so use it "as is", with no promises made! :)

It also uses calls to my internal "DumpLog" wrapper function that your code won't have (it essentially just writes to Game.LogTrivial, but dumps various other things as well). You'll need to make changes to each one of those logging references!

 

 

 


using System.Reflection;
using System.Net;
using System.IO;

----snip----

       static void MaybeCheckForUpdates()
        {
            // determine if we should check for updates

            bool shouldCheckForUpdates = false;
            DateTime lastUpdateCheck = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

            try
            {
                InitializationFile baseIni = new InitializationFile(Directory.GetCurrentDirectory() + "\\Plugins\\LSPDFR\\CHANGEME.ini");

                shouldCheckForUpdates = baseIni.ReadBoolean("CHANGEME", "CheckForUpdates", true);

                string dateLastCheckedForUpdates = baseIni.ReadString("CHANGEME", "LastUpdateCheck", "1970-01-01");
                bool couldParseDateTime = DateTime.TryParse(dateLastCheckedForUpdates, out lastUpdateCheck);

                if (!couldParseDateTime)
                {
                    CommonUtils.DumpLog("OnOnDutyStateChanged", "ParseIniForUpdate", "CHANGEME is unable to parse the string '" + dateLastCheckedForUpdates + "'  from the ini file as a DateTime.");
                    CommonUtils.DumpLog("OnOnDutyStateChanged", "ParseIniForUpdate", "CHANGEME will therefore not check for updates.");
                }

            }
            catch (Exception e)
            {
                CommonUtils.DumpLog("OnOnDutyStateChanged", "ParseINIForUpdate", "Unable to parse CHANGEME.ini to check for software update preference.");
                CommonUtils.DumpLog("OnOnDutyStateChanged", "ParseINIForUpdate", "InnerException", e.ToString());
            }

            GameFiber.StartNew(delegate
            {
                if (shouldCheckForUpdates && lastUpdateCheck.AddDays(1) < DateTime.Now)
                {
                    try
                    {

                        // write update check time
                        try
                        {
                            InitializationFile writeableBaseIni = new InitializationFile(Directory.GetCurrentDirectory() + "\\Plugins\\LSPDFR\\CHANGEME.ini");
                            writeableBaseIni.Write("CHANGEME", "LastUpdateCheck", DateTime.Now.ToString("yyyy-MM-dd"));
                        }
                        catch (Exception e)
                        {
                            CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "LastUpdateCheckWriter", "Could not write last update check time.");
                            CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "LastUpdateCheckWriter", e.ToString());
                        }


                        // allow a random time before running update check
                        DateTimeOffset unixTimestamp = DateTimeOffset.Now;
                        long unixTimestampMicroSeconds = unixTimestamp.ToUnixTimeMilliseconds();

                        Random updateCheckerRandom = new Random((int)unixTimestampMicroSeconds);
                        int waitTime = updateCheckerRandom.Next(7500, 45000);

#if DEBUG
                        CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Waiting " + waitTime.ToString() + "ms before update check attempt");
#endif

                        GameFiber.Sleep(waitTime);


                        // download from LCPDFR.com Update Check API endpoint
                        WebClient updateChecker = new WebClient();
                        Version currentVersion = new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString());
                        Version updateVersion;

                        updateChecker.Headers.Add("User-Agent", "CHANGEME/" + currentVersion.ToString());

                        string updateReply = "";

                        try
                        {
                            updateReply = updateChecker.DownloadString("http://www.lcpdfr.com/applications/downloadsng/interface/api.php?do=checkForUpdates&fileId=CHANGEME&textOnly=1");
                        }
                        catch (WebException webException)
                        {
                            CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Unable to check for updates to CHANGEME: " + webException.ToString());
                        }

                        if (updateReply.Length > )
                        {
                            try
                            {


                                updateVersion = new Version(updateReply);

#if DEBUG
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Retrieved version string is " + updateVersion.ToString());
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Current version string is " + currentVersion.ToString());
#endif

                                if (updateVersion > currentVersion)
                                {
                                    Game.DisplayNotification("An ~g~update~w~ to ~b~CHANGEME~w~ is available. Please visit LCPDFR.com to download it.");
                                    Game.DisplayNotification("You can turn off automatic update checking in ~y~CHANGEME.ini~w~ in ~y~plugins/LSPDFR~w~.");
                                }
                                else
                                {
                                    CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "CHANGEME checked for updates and is up to date. Updates will be checked again on the next calendar day that you go on duty.");
                                }

                            }
                            catch (ArgumentException ae)
                            {
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Unable to check for updates to CHANGEME. Got an ArgumentException parsing retrieved version string " + updateReply);
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "InnerException", ae.ToString());
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "This might mean that LCPDFR.com is down, or not responding normally.");
                            }
                            catch (FormatException fe)
                            {
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Unable to check for updates to CHANGEME. Got an FormatException parsing retrieved version string " + updateReply);
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "InnerException", fe.ToString());
                                CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "This might mean that LCPDFR.com is down, or not responding normally.");
                            }

                        }

                    }
                    catch (Exception e)
                    {
                        CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Unable to check for updates to CHANGEME. Outer catch. Exception: " + e.ToString());
                    }
                }
                else
                {
#if DEBUG
                    CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Won't check for updates, as this feature is turned off, or we already checked for updates too recently.");
                    CommonUtils.DumpLog("OnOnDutyStateChanged", "CHANGEMEUpdateCheck", "Last update check: " + lastUpdateCheck.ToString("yyyy-MM-dd"));
#endif
                }
            }, "CHANGEMEUpdateCheck");
        }

 

 

Edited by PeterU
Removed my plugin's fileId from the URL string -- you need to put yours in there instead!

As you might guess, I make PeterUCallouts. I love working to bring LSPDFR players the kind of callouts that strike a good balance between realism and fun and are stable & varied!

Unfortunately I cannot offer support via PM -- please use the forums, so that others may benefit from your solutions!

  • 11 months later...

An update to my update checking mechanism. Now I run the actual HTTP requests inside a non-GameFiber Thread, which means the game doesn't drop frames while we wait for the HTTP response.

 

https://gist.github.com/LSPDFR-PeterU/952de66a4f17b838d3870bdaabb6c43b

As you might guess, I make PeterUCallouts. I love working to bring LSPDFR players the kind of callouts that strike a good balance between realism and fun and are stable & varied!

Unfortunately I cannot offer support via PM -- please use the forums, so that others may benefit from your solutions!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Similar Content

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.