Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add tilde symbol (~) & expand environment variables#114102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
AR-DEV-1 wants to merge19 commits intogodotengine:master
base:master
Choose a base branch
Loading
fromAR-DEV-1:13823-imp

Conversation

@AR-DEV-1
Copy link
Contributor

TL;DR

This PR adds the tilde symbol (which is used in UNIX based OS). It checks for your platform & expands the tilde symbol to your home dir (which isUSERPROFILE on Windows &HOME on Linux). Currently, this PR has to expand the environment variables (I'm working on that, just not pushed yet).

Zireael07, AR-DEV-1, and Aratch reacted with thumbs up emoji
@AR-DEV-1AR-DEV-1 requested a review froma team as acode ownerDecember 17, 2025 09:53
@AR-DEV-1AR-DEV-1 marked this pull request as draftDecember 17, 2025 09:53
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@AThousandShips
Copy link
Member

You are once again using spaces instead of tabs, please set upclang-format to automate fixing this

@AR-DEV-1
Copy link
ContributorAuthor

@AThousandShips This is the new logic in which the environment variables are expanded. Is it acceptable?

static String _expand_windows_env_vars(const String &p_path) {String path = p_path;int from = 0;while ((from = path.find("%", from)) != -1) {int to = path.find("%", from + 1);if (to == -1) {break;}String var = path.substr(from + 1, to - from - 1);if (var.is_empty()) {from = to + 1;continue;}String value = OS::get_singleton()->get_environment(var);if (!value.is_empty()) {path = path.substr(0, from) + value + path.substr(to + 1);from += value.length();} else {from = to + 1;}}return path;}static bool _is_env_char(char32_t c) {return c == '_' || (c >= 'A' && c <= 'Z') ||       (c >= 'a' && c <= 'z') ||       (c >= '0' && c <= '9');}static String _expand_unix_env_vars(const String &p_path) {String path = p_path;int i = 0;while ((i = path.find("$", i)) != -1) {int start = i + 1;int end = start;while (end < path.length() && _is_env_char(path[end])) {end++;}if (end == start) {i++;continue;}String var = path.substr(start, end - start);String value = OS::get_singleton()->get_environment(var);if (!value.is_empty()) {path = path.substr(0, i) + value + path.substr(end);i += value.length();} else {i = end;}}return path;}String FileDialog::expand_path(const String &p_path) {    String path = p_path;    if (path.begins_with("~")) {#ifdef WINDOWS_ENABLED        String home = OS::get_singleton()->get_environment("USERPROFILE");#else        String home = OS::get_singleton()->get_environment("HOME");#endif        if (!home.is_empty()) {            path = home + path.substr(1);        }    }#ifdef WINDOWS_ENABLEDpath = _expand_windows_env_vars(path);#elsepath = _expand_unix_env_vars(path);#endifreturn path;}

@AThousandShips
Copy link
Member

Can't really speak to it, but easier to review if you just update the PR with it

AR-DEV-1 reacted with thumbs up emoji

AR-DEV-1and others added3 commitsDecember 17, 2025 15:36
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@AR-DEV-1AR-DEV-1 changed the titleAdd tilde symbol (~) in FileDialog folder/file path fields & expand environment variablesAdd tilde symbol (~) & expand environment variablesDec 17, 2025
Copy link
Member

@AThousandShipsAThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You haven't declared it inos.h though, did you run this code or did you just forget to include that file in the push?

AR-DEV-1and others added2 commitsDecember 17, 2025 21:03
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@AR-DEV-1
Copy link
ContributorAuthor

You haven't declared it inos.h though, did you run this code or did you just forget to include that file in the push?

I forgot. Should I push that with the declaration inos.h or should I leave it to os_unix & os_windows?

@AThousandShips
Copy link
Member

The code won't work without it so you need to add it toos.h

The default method should probably just return the input string unchanged, but we'd need to check if any other platform needs it (that don't useOS_Unix as a base)

AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

@AThousandShips Should I just declare inos.h & remove the declaration fromos_unix.h &os_windows.h? It may not cause any more errors?

@AThousandShips
Copy link
Member

AThousandShips commentedDec 17, 2025
edited
Loading

No you should just addvirtual String expand_path(const String &p_path) const; toos.h and an implementation inos.cpp, orvirtual String expand_path(const String &p_path) const = 0; and implement it in all platforms where needed, or justvirtual String expand_path(const String &p_path) const { return p_path; } but I'd put it in the cpp file to make it easier to modify if needed

It should be separate for each OS as it's different in each, unless it doesn't need to be and both can useHOME I'm not familiar with this

@AR-DEV-1
Copy link
ContributorAuthor

AR-DEV-1 commentedDec 17, 2025
edited
Loading

No

I was thinking aboutvirtual String expand_path(const String &p_path) const override; as the main declaration inos.h because Windows & Unix are different (will still have to keep the logic apart, Linux usesHOME & Windows usesUSERPROFILE

@AThousandShips
Copy link
Member

AThousandShips commentedDec 17, 2025
edited
Loading

I don't understand what you mean my suggestion is to addvirtual String expand_path(const String &p_path) const; toos.h andString OS::expand_path(const String &p_path) const { return p_path; } toos.cpp

Just add the code you forgot to include that works on your local machine and we can go from there

AR-DEV-1 reacted with thumbs up emoji

@AThousandShips
Copy link
Member

Please build the code locally to avoid pushing so many times with simple errors in the code and to make sure your PR actually works

AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

Please build the code locally to avoid pushing so many times with simple errors in the code and to make sure your PR actually works

Is there a git command to push & not cause CI to run?

@AThousandShips
Copy link
Member

Yes you can add[no ci] to the commit message, but you really should test a PR, did you build this at all?

AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

Yes you can add[no ci] to the commit message, but you really should test a PR, did you build this at all?

Yes, my build took some time but also failed. I'll start using[no ci] now.

@AThousandShips
Copy link
Member

Please just update your local branch, confirm it builds and fix any issues with it if it doesn't, and then push, no reason to push before you know it's actually correct

AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

Please just update your local branch, confirm it builds and fix any issues with it if it doesn't, and then push, no reason to push before you know it's actually correct

Sorry, will do now.

AThousandShips reacted with thumbs up emoji

@AThousandShips
Copy link
Member

AThousandShips commentedDec 18, 2025
edited
Loading

This looks quite good! I have one concern though:
~ is, as far as I know, permitted in file names, on Windows it was used for trimmed names back in the 8.3 file name format restrictions, so for exampleFOOBARBAZ.TXT would becomeFOOBARB~.TXT, and from what I can find names can start with a~, and I can't find anything in POSIX about banning them, so I'd make the check check that it's a path starting with~/ (or~\\) to prevent~foo.txt being mangled

Leading~ is also regularly used for temporary lock files or backups etc.

Also are you still planning to add environment variable expansion support? Otherwise I'd remove it from the description and title

@bruvzg
Copy link
Member

~ is, as far as I know, permitted in file names

It is, and not only on Windows (works on macOS as well). And it is permitted as the first (or only) character of the folder names. So it might cause issues with relative paths.

AThousandShips and AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

AR-DEV-1 commentedDec 18, 2025
edited
Loading

This looks quite good! I have one concern though:~ is, as far as I know, permitted in file names, on Windows it was used for trimmed names back in the 8.3 file name format restrictions, so for exampleFOOBARBAZ.TXT would becomeFOOBARB~.TXT, and from what I can find names can start with a~, and I can't find anything in POSIX about banning them, so I'd make the check check that it's a path starting with~/ (or~\\) to prevent~foo.txt being mangled

Leading~ is also regularly used for temporary lock files or backups etc.

Also are you still planning to add environment variable expansion support? Otherwise I'd remove it from the description and title

Thanks! Took some time but now works as intended.
Firstly, I didn't know that this could happen on Windows. I'll update the code to~/ &~\\ on Windows so it won't interfere with lockfiles, backups & etc (Can be done viaif (path.begins_with("~/") || path.begins_with("~\\")), I suppose? Unix will be updated to use~/ because~\\ is not supported)
Secondly, yes. Environment variables are on my mind so I think support will be added for them (If I'm positive I can't add support for them, I'll remove them)

@AR-DEV-1
Copy link
ContributorAuthor

@AThousandShips Should I also updateEditorFileDialog now?

@AThousandShips
Copy link
Member

Does that dialog need this? It is derived fromFileDialog so it should share the same code generally unless it's not in the shared code

AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

Does that dialog need this? It is derived fromFileDialog so it should share the same code generally unless it's not in the shared code

No, you are correct. Same code is shared.

@AR-DEV-1
Copy link
ContributorAuthor

@bruvzg Can you test the logic on MacOS?

@AR-DEV-1
Copy link
ContributorAuthor

@AThousandShips If you are on Windows, can you test the logic?

@AThousandShips
Copy link
Member

I can try later when I have the time to build, but I don't think this should be ignored for CI unless you're going to update it more soon, assuming it compiles locally, assuming you are on Linux so you can test the Linux side

AR-DEV-1 reacted with thumbs up emoji

@AR-DEV-1
Copy link
ContributorAuthor

I can try later when I have the time to build, but I don't think this should be ignored for CI unless you're going to update it more soon, assuming it compiles locally, assuming you are on Linux so you can test the Linux side

I'll upload an MRP. Linux works fine, just have to confirm on Windows & MacOS. I'll not ignore the CI for the next change.

@AThousandShips
Copy link
Member

No MRP needed, I just need to build it and it'll take a little bit sinceos.h is changed, not serious but just gotta set aside the time

@AR-DEV-1
Copy link
ContributorAuthor

No MRP needed, I just need to build it and it'll take a little bit sinceos.h is changed, not serious but just gotta set aside the time

Alright, tell me if you encounter any problems/issues

@bruvzg
Copy link
Member

Can you test the logic on MacOS?

Will check it tomorrow.

AR-DEV-1 reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@AThousandShipsAThousandShipsAThousandShips left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

None yet

Milestone

4.x

Development

Successfully merging this pull request may close these issues.

Expand environment variables and tilde symbol (~) in FileDialog folder/file path fields

3 participants

@AR-DEV-1@AThousandShips@bruvzg

[8]ページ先頭

©2009-2025 Movatter.jp