PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label mono. Show all posts
Showing posts with label mono. Show all posts

Sunday, November 6, 2022

[FIXED] How to detect properly Windows, Linux & Mac operating systems

 November 06, 2022     c#, cross-platform, macos, mono     No comments   

Issue

I could not found anything really efficient to detect correctly what platform (Windows / Linux / Mac) my C# progrma was running on, especially on Mac which returns Unix and can't hardly be differenciated with Linux platforms !

So I made something less theoretical, and more practical, based on specificities of Mac.

I'm posting the working code as an answer. Please, comment if it works well for you too / can be improved.

Thanks !

Response :

Here is the working code !

    public enum Platform
    {
        Windows,
        Linux,
        Mac
    }

    public static Platform RunningPlatform()
    {
        switch (Environment.OSVersion.Platform)
        {
            case PlatformID.Unix:
                // Well, there are chances MacOSX is reported as Unix instead of MacOSX.
                // Instead of platform check, we'll do a feature checks (Mac specific root folders)
                if (Directory.Exists("/Applications")
                    & Directory.Exists("/System")
                    & Directory.Exists("/Users")
                    & Directory.Exists("/Volumes"))
                    return Platform.Mac;
                else
                    return Platform.Linux;

            case PlatformID.MacOSX:
                return Platform.Mac;

            default:
                return Platform.Windows;
        }
    }

Solution

Maybe check out the IsRunningOnMac method in the Pinta source:



Answered By - TheNextman
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, September 18, 2022

[FIXED] What is the best way to print a Gtk.Widget to the printer?

 September 18, 2022     gtk, mono, printing     No comments   

Issue

I have a couple of (mostly) text widgets that I would like to render to a printer through a standard "Print..." menu option. One widget is a Mono.TextEditor document, and the other is a Gtk.TextView.

I'm looking for a pretty basic print for now, which might wrap long lines, and add page numbers. Do I need to code all of this myself somehow?

If you have pointers, that would be great, especially if they were in C#.


Solution

For line wrap and justification, one can use pango Layout options, as described for Python at pygtk/class-pangolayout or for C at pango/pango-Layout-Objects. See functions pango_layout_set_wrap() and pango_layout_set_justify().

Also see the example-code routines begin_print, do_page_setup, and do_print in file pygtk-demo/demos/print_editor.py, if you have installed pygtk on your system. (On my system, the full path to directory of Python Gtk demo files currently is /usr/share/doc/pygtk2-2.17.0/examples/pygtk-demo/demos)

For printer setup dialog, see gtk-High-level-Printing-API for C, or class-gtkprintoperation for Python.



Answered By - James Waldby - jwpat7
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, September 12, 2022

[FIXED] How Do I get the "friendly" name of serial port in Mono and keep it cross platform

 September 12, 2022     .net, cross-platform, linux, mono, serial-port     No comments   

Issue

I asked this question:
Serial Port (rs232) in Mono for multiple platforms

and this one is related:
How do I get the friendly name of a COM port in Windows?

But I want to be able to get the "friendly" name on Windows- and possibly also on linux /mac if there is such a thing.

Is there any cross platform way to do it, or am I out of luck?

Here is what I am doing in my current app - and it works great for native C++ win32.

http://www.naughter.com/enumser.html

In any case it does not look like a pretty solution for cross-platform distribution. Does anyone have any suggestions?

EDIT - since people are having trouble understanding what I am asking for: as an example - COM9 is not a friendly name. I want something that says "COM9 - USB connector" or something like that. This is possible with the link above in Win32. It is nasty and hacky, but many times end users have no idea what COM port they need to open in my program unless there is a useful name - more useful than "COMn."


Solution

AFAIK there is no "friendly" name for the COMM devices in linux. What I suggest you do is use the /dev/ttyS# as your device name in a linux environment and list them as COMM# in windows.

The linux users will understand the terminology so there shouldn't be a worry there.



Answered By - Tanj
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, April 27, 2022

[FIXED] What exactly happens when a MonoBehaviour is created with new?

 April 27, 2022     c#, compiler-warnings, mono, unity3d, warnings     No comments   

Issue

I'm aware that it's "not allowed"; I did this by accident and it will thoroughly be removed from my final build. Obviously there's a good reason for that rule.

The weird thing is, it's in a unit testing component, and it still works perfectly in spite of the warning. I was filling a list with a few constructed instances of a class inheriting from MonoBehaviour, just to ensure that a function was doing what I wanted it to do, and I get this warning; but the test seems to run fine. Additionally, this is a warning, not an true error, which likely also has a reason.

Out of curiosity, as my understanding is clearly incomplete, can someone explain, and if possible provide a link to documentation explaining, why it is that Unity does not allow a behavior which it is clearly quite capable of? Why does it forbid this, and, in the event that the warning was ignored, what would be the drawbacks?

Thank you for completing my comprehension of it.


Solution

Unity has a component-based architecture. Any object that exists in a scene is represented by a GameObject which has one or more Component objects attached to it.

Components frequently change the behavior or appearance of the GameObject that they are attached to. In some cases, Components also reference or depend on each other. As an example, RigidBody and Collider components tend to be used in tandem.

MonoBehaviour scripts are also derived from the Component class. You can potentially create a behavior object using new, but it won't be attached to any GameObject and therefore won't properly exist in the scene. This is likely to lead to errors:

  • Built-in events may not work consistently. For example, Awake, Start, Update, or OnCollisionEnter.
  • Built-in references won't work at all. For example, gameObject, transform, or the AddComponent and GetComponent family of functions.
  • Unsafe for other components to interact with this component in a standard way.
  • Scene transitions are likely to compound the problem, since your orphaned script won't be attached to anything in the scene.

You do have some other options, though.

You can create a new GameObject, and then attach your script to it. This is a common workflow for scripts that will be managing game state for an entire scene (or across multiple scenes). This may fall under a singleton pattern.

You can also create classes that do not derive from MonoBehaviour, if you need those classes to be usable outside of a scene.



Answered By - rutter
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing