Unity3D-Wine-Support / Unity3D-on-Wine

Scripts for making Unity3D run on Wine.
GNU General Public License v2.0
102 stars 59 forks source link

Open files from Unity in a native MonoDevelop #38

Open jurf opened 9 years ago

jurf commented 9 years ago

Moved from #37.

I've looked at what arguments the editor passes to MonoDevelop. I wrote a little script that writes the arguments into a file:

#!/bin/sh
echo "$@" >> ~/unity_arguments

named it MonoDevelop.exe, made it executable and put it in place of Unity/Monodevelop/bin/MonoDevelop.exe. When I opened a file in Unity, I got the arguments written into the file, and they look like this:

--nologo C:\path\to\project-name\project-name.sln C:\path\to\file.cs;-1

Now just to figure out how to tell Unity to include the project file location and change it to the C# only version and create a script which converts the paths to unix.

Radivarig commented 9 years ago

There are two problems with monodevelop not opening files. 1) The following does not open the file monodevelop .local/share/wineprefixes/unity3d/dosdevices/c\:/users/radivarig/My\ Documents/Projects/Unity3d/uccnodeeditorfix/Assets/AssetHandling.cs while same command with subl instead monodevelop opens file correctly. So, I decided to write a script that will just change directory and let MD deal with easy file name path. BUT it worked with sln and not with .cs file (both from Unity arguments) which brings us to second problem 2) ;-1 line_number part in name has to be >=0 :) Here is the full script that loads .sln and opens the file on correct line save it as MonoDevelop.exe, give execution rights chmod +x in place of builtin MD drive_c/Program Files/Unity/MonoDevelop/bin/MonoDevelop.exe

#!/bin/sh
if [ -z "$1" ]; then exit 1; fi;

SLN_PATH=$(winepath -u "$2")
FILE_PATH_AND_LINE=$(winepath -u "$3")

ONLY_PATH=$(dirname "$SLN_PATH")

SLN_NAME="${SLN_PATH#$ONLY_PATH}"
SLN_NAME="${SLN_NAME#?}"

FILE_PATH_AND_LINE_NAME="${FILE_PATH_AND_LINE#$ONLY_PATH}"
FILE_PATH_AND_LINE_NAME="${FILE_PATH_AND_LINE_NAME#?}"
LINE="${FILE_PATH_AND_LINE_NAME##*;}"
FILE_PATH_AND_LINE_NAME="${FILE_PATH_AND_LINE_NAME%;$LINE}"

if [ $LINE == "-1" ]; then LINE="0"; fi;

cd "$ONLY_PATH"
/bin/monodevelop "$SLN_NAME $FILE_PATH_AND_LINE_NAME;$LINE"

exit 0
jurf commented 9 years ago

OK, just tested this. Great work!

Three (potential) issues: 1: the unity_arguments file will slowly grow in size, and will annoy most people since they probably won't ever use it 2: it still doesn't use the C# .sln file, so it produces errors on startup 3: I'm still scratching myself on the head why Unity calls MonoDevelop with line -1. I tried commenting the "if line is -1" part and it worked! Maybe it's better to leave it as it is.

Could you create a patch request with this script? Thanks.

Radivarig commented 9 years ago

1: echoing was just for debugging paths (removed it from above) 2: I pinpointed the problem for references here #39 3: running monodevelop "file.cs;-1" didn't work for me

Sure :)

Radivarig commented 9 years ago

Noticed that I had manually opened c# sln before so now I see the error you mentioned. I fixed this by replacing ".sln" with "-csharp.sln". However there is a problem with monodevelop itself and paths (it doesn't work in terminal... subl opens paths perfectly), so paths are correct but MD doesn't get them right, in the script I change directory to the dirname of ".sln" file, that's why it opened it correctly. I can also open correctly files only without .sln but I am testing solution with symlinks for both.

Radivarig commented 9 years ago

Fixed! MD can't handle any spaces in the path.. I tried escaping, placing in string, symlinked (which worked but MD couldn't match symlinked path with .sln ...) so what I did is: -counted folders in file path (local to .sln file) -changed dir to file folder -called MD with {../ times folder count +.sln} +filename :)

https://github.com/Radivarig/Unity3D-on-Wine/blob/master/text-editors-MonoDevelop/unity3d_native_monodevelop.sh