.NET Coldfire202's C# Updater GitHub Thread

Discussion in 'Source Code & Tutorial Database' started by MatthewH, Apr 15, 2015 with 28 replies and 1,798 views.

  1. Im4eversmart

    Im4eversmart The hacks are real

    Messages:
    2,098
    Ratings:
    1,669
    That was my intention. I just didn't type it word for word. If it's too much work, do the second thing which is string comparison. It's not hard either way.
     
  2. Mr Smithy x

    Mr Smithy x Enthusiast

    Messages:
    328
    Ratings:
    180
    This is here just to simulate if you were to download from the internet
    Code:
    class ver
    {
        public string version = "2.23.4.1";
    }
    
    Major.Minor.Build.Revision
    -1 = Lower Version
    1 =New Version
    0 = Same Version
    Code:
                string jsonVersion = JsonConvert.SerializeObject(new ver()); //example ie: downloading from the internet
                Console.WriteLine(jsonVersion); //just printing out the json
    
                JObject j = (JObject)JsonConvert.DeserializeObject(jsonVersion);
                string version = j["version"].ToString();
               
    Version file = Version.Parse(Application.ProductVersion); //Application Product Version
    
                Version custfile = new Version(2, 23, 4, 1); //Version Example
    
                Version netVersion = Version.Parse(version); //Version "Downloaded" from internet
    
                Version triVersion = Version.Parse("2.23.4"); //Version with just 2 decimals
    
                Version triVersion2 = Version.Parse("2.23.5"); //Version with just 2 decimals
    
                int check = file.CompareTo(netVersion);
                Console.WriteLine(check); // -1 file < netVersion
    
                check = netVersion.CompareTo(file);
                Console.WriteLine(check); // 1 netVersion > file
    
                check = custfile.CompareTo(netVersion);
                Console.WriteLine(check); // 0 custfile == netVersion
    
                check = triVersion.CompareTo(netVersion);
                Console.WriteLine(check); // -1 triVersion < netVersion
    
                check = triVersion2.CompareTo(netVersion);
                Console.WriteLine(check); // 1 triVersion2 > netVersion
                
     
    Last edited: Apr 20, 2015
  3. OP
    MatthewH

    MatthewH Member

    Messages:
    1,612
    Ratings:
    613
    You're still writing way more code than what is logical in my opinion. Doesn't matter how you do it.

    Doing one check, the build number is way easier and more efficient than doing 2, 3, or 4 checks. Or even working with strings, strings are unreliable especially with comparisons.
    Believe me, I've tried to do a good bit with strings. I minimize my string usage as much as possible.
     
  4. Im4eversmart

    Im4eversmart The hacks are real

    Messages:
    2,098
    Ratings:
    1,669
    If you want to use a hierarchy for versions, use code one. If you want to directly compare server to app version with no parsing, use code two. If you want to just do integer comparison, use an integer for a build number, not a string.

    Code:
    String[] server = String.split(".");
    String[] app = String.split(".");
    
    for(int i = 0; i  < server.length; i++){
    if(Integer.parse(server[i]) > Integer.parse(app[i])) return true;
    else if(Integer.parse(app[i]) > Integer.parse(server[i]))
    return false;
    }
    return false;
    Code:
    String server;
    String app;
    return !server.equals(app);
     
  5. Mr Smithy x

    Mr Smithy x Enthusiast

    Messages:
    328
    Ratings:
    180
    The string is reliable in this situation no matter what way you put it and the checks were there so you can see whats going on behind the scenes... besides using version is as simple as it gets, just set ur version the in the project settings... and its 3-5 lines of code max....
     
    Last edited: Apr 20, 2015
  6. OP
    MatthewH

    MatthewH Member

    Messages:
    1,612
    Ratings:
    613
    I've grown wearisome of this endless debate.
    If you don't contribute to the project then don't say anything. It's my way of doing it; I prefer it.
    If you really care about it, go ahead and contribute a new solution to it. Simple as that.
     
  7. Mr Smithy x

    Mr Smithy x Enthusiast

    Messages:
    328
    Ratings:
    180
    I'm pretty sure showing ways a sematic update can be done is contributing, and like you said sematic versioning is the good one to use, which is what i posted.
     
  8. Lobfischer

    Lobfischer Newbie

    Messages:
    1
    Ratings:
    0
    yas! w4s t0t4lly l00k1ng f0r th1s! thx m8
     
  9. Xeren

    Xeren ♦♦♦ God Complex ♦♦♦

    Messages:
    5,678
    Ratings:
    1,890
    You require three lines to grab both versions and then compare, and so does his method, which is more efficient if people use any more than one digit per version type.
     
    • Like Like x 1

Share This Page