OS-aware Proof-of-Concept

Discussion in 'Programming' started by aidancheddar, Mar 2, 2015.

  1. aidancheddar

    aidancheddar Active Member

    Having fiddled with processors on my own repository, I decided to try out on @francot514's TSOCategorizer. I know he barely touches it but since it makes use of PD's APIs, it makes for excellent way to get your hands dirty in the TSO.Files APIs. So, I wondered, would it be possible to have TSOCategorizer work on Linux? Right now, it can but not without Wine. This is because of the Microsoft.Win32 package. Thankfully, it only makes use of it once. So, after much trial and error, it worked! Unfortunately, I don't have a Linux VM on me at the moment but if you swap !UNIX with UNIX and vice verse, yeah. I also used the if (Environment.Is64BitOperatingSystem && Environment.Is64BitProcess) logic from PD itself for detecting systems on 32bit installations. Apparently, Mono doesn't have those Unix processors. Created a simpler implantation below.

    Code:
    #if !UNIX
    using Microsoft.Win32;
    #endif
    Code:
    #if !UNIX
                string autoRegSoft;
    
                if (Environment.Is64BitOperatingSystem && Environment.Is64BitProcess){
                    autoRegSoft = "SOFTWARE";
                } else {
                    autoRegSoft = "SOFTWARE\\Wow6432Node";
    
                }
    
                if (Registry.GetValue("HKEY_LOCAL_MACHINE\\" + autoRegSoft + "\\Maxis\\The Sims Online", "InstallDir", null) == null)
                {
    
    
                    // Displays a message box with the yes and no options.
                    DialogResult Response = MessageBox.Show("Please select TSO Game Folder", "TSO Game Installation", MessageBoxButtons.OKCancel);
    
                    // If statement to check if the yes button was selected.
                    if (Response == DialogResult.OK)
                    {
                        folderBrowserDialog1.ShowDialog();
                        Properties.Settings.Default.Gamepath = folderBrowserDialog1.SelectedPath;
                        Properties.Settings.Default.Save();
                        gamedir = folderBrowserDialog1.SelectedPath;
    
                    }
                    else
                    {
                        // The no button was selected.
                        MessageBox.Show("Now you cannot preview files");
                        Application.Exit();
                    }
    
                }
                else
                {
                    regvalue = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + autoRegSoft + "\\Maxis\\The Sims Online", "InstallDir", null).ToString();
                    Properties.Settings.Default.Gamepath = regvalue;
                    Properties.Settings.Default.Save();
                    gamedir = regvalue;
    
                }
    
    #elif UNIX
                // Displays a message box with the yes and no options.
                DialogResult Response = MessageBox.Show("Please select TSO Game Folder", "TSO Game Installation", MessageBoxButtons.OKCancel);
                if(Response == DialogResult.OK)
                {
                    folderBrowserDialog1.ShowDialog();
    
                    Properties.Settings.Default.Gamepath = folderBrowserDialog1.SelectedPath;
    
                    gamedir = folderBrowserDialog1.SelectedPath;
                }
                else
                {
                    MessageBox.Show("Now you cannot preview files");
                    Application.Exit();
                }
    #endif
    Last edited: Mar 3, 2015
  2. francot514

    francot514 Well-Known Member

    For use it with linux i have installed Mono for linux, dont know which version of unix youre using... and which compiller debugger way you tried...
  3. aidancheddar

    aidancheddar Active Member

    It's generic and refers to OS X or Linux. I was only able to try with Visual Studio but the preprocessors work as they should.
  4. aidancheddar

    aidancheddar Active Member

    Finally got a Linux VM up. So, Mono doesn't know the the UNIX as a conditional statement. More testing!
  5. aidancheddar

    aidancheddar Active Member

    After going over tones of Mono documentation and revisiting stack overflow, I created a much simpler solution.
    Code:
    if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
             string autoRegSoft;
    
             if (Environment.Is64BitOperatingSystem && Environment.Is64BitProcess) {
               autoRegSoft = "SOFTWARE";
             } else {
               autoRegSoft = "SOFTWARE\\Wow6432Node";
    
             }
    
             if (Registry.GetValue ("HKEY_LOCAL_MACHINE\\" + autoRegSoft + "\\Maxis\\The Sims Online", "InstallDir", null) == null) {
    
    
               // Displays a message box with the yes and no options.
               DialogResult Response = MessageBox.Show ("Please select TSO Game Folder", "TSO Game Installation", MessageBoxButtons.OKCancel);
    
               // If statement to check if the yes button was selected.
               if (Response == DialogResult.OK) {
                 folderBrowserDialog1.ShowDialog ();
                 Properties.Settings.Default.Gamepath = folderBrowserDialog1.SelectedPath;
                 Properties.Settings.Default.Save ();
                 gamedir = folderBrowserDialog1.SelectedPath;
    
               } else {
                 // The no button was selected.
                 MessageBox.Show ("Now you cannot preview files");
                 Application.Exit ();
               }
    
             } else {
               regvalue = Registry.GetValue ("HKEY_LOCAL_MACHINE\\" + autoRegSoft + "\\Maxis\\The Sims Online", "InstallDir", null).ToString ();
               Properties.Settings.Default.Gamepath = regvalue;
               Properties.Settings.Default.Save ();
               gamedir = regvalue;
    
             }
    
           } else {
             // Displays a message box with the yes and no options.
             DialogResult Response = MessageBox.Show ("Please select TSO Game Folder", "TSO Game Installation", MessageBoxButtons.OKCancel);
             if (Response == DialogResult.OK) {
               folderBrowserDialog1.ShowDialog ();
    
               Properties.Settings.Default.Gamepath = folderBrowserDialog1.SelectedPath;
    
               gamedir = folderBrowserDialog1.SelectedPath;
             } else {
               MessageBox.Show ("Now you cannot preview files");
               Application.Exit ();
             } 
    
    Ubuntu.png
    Little crashy, though.
    Last edited: Mar 3, 2015
  6. francot514

    francot514 Well-Known Member

    Ok, not doing the code for cross platform was my mistake, i was not thinking about be able to use it, just used the mono runtime, becuase is supposed to have better implementation that the net framework...
    Good to know you can do it, also i have some extra code think youre missing from ObjectsData, youre change the implementation to sims 1??
  7. aidancheddar

    aidancheddar Active Member

    Same implementation. Just reading directly from TSO.Files source code itself instead of an pre-compiled platform-dependent DLL. It is having trouble reading the ObjectData, though, since it's using the newer TSO.Files.
    Last edited: Mar 4, 2015
  8. francot514

    francot514 Well-Known Member

    Ok, whats your main objective?? recreate the application with your own code, or improve the current one and allow use of it for unix system?? I can always give you a hand if needed...
  9. aidancheddar

    aidancheddar Active Member

    Well, the purpose is the find the best way to get these applications and Project Dollhouse itself that are designed to normally look for The Sims or The Sims Online via registry to also have a fallback manual method if they're on Unix systems, such as Linux or Mac OS X. Now that the game has been fully ported to MonoGame, a method of locating The Sims Online non-Windows systems is needed.

    Your applications makes a good test bed since it's not as complex as Project Dollhouse but still uses it's libraries and method of locating the game.
  10. RHY3756547

    RHY3756547 FreeSO Developer Staff Member Moderator

    This was never going to be a problem for us, but it's good that you tried it out and got it working. For linux we would want to remember the directory the user first specifies, or better yet, download the game using the patcher itself (once it's not so buggy).
  11. aidancheddar

    aidancheddar Active Member

    Thanks. Seeing as I much more prefer Linux then I do Windows, this is something I wanted to get off my chest and try it now. Both to see if I can get it working to begin with and as practice now that I'm throwing the books aside only for reference.
    I've had that same idea. XD
  12. RHY3756547

    RHY3756547 FreeSO Developer Staff Member Moderator

    Once we're ready for more distributed testing, I'll clean up the patcher as mentioned to both download the game and patch without randomly crashing. It'll also probably look like the original patcher, for that nostalgic feel. ;)
  13. aidancheddar

    aidancheddar Active Member

    Nostalgia or not, I always did like TSO's patcher design.
  14. francot514

    francot514 Well-Known Member



    Programming for Linux is quite complicated, which compiler you will use???, also remember that for now only PD has some linux compatibilty, but for sims 1 it will not have a way to test your experimental tools...
  15. aidancheddar

    aidancheddar Active Member

    For C#? Not really. Especially with .NET Core (then official open source cross-platform version) and Microsoft giving the green light for anyone to implant any .NET 4.0 features that aren't in the C# standard. Meaning will be compatible with newer C# apps then innthe past.
    Mono on Linux, .NET on Windows.
    That's why the experimental projects are there. That and gain expreince. xD
    Last edited: Mar 6, 2015
  16. miceiken

    miceiken New Member

    Environment.Is64BitProcess
    Code:
    sizeof(IntPtr) == 8
  17. aidancheddar

    aidancheddar Active Member

    Thanks... I prefer not to reinvent the wheel on such a small project, like TSOCategorizer.

Share This Page