Differences between running OSX App from Finder versus Xcode?

与世无争的帅哥 提交于 2019-12-02 07:51:34

问题


Differences between running OSX App from Finder versus Xcode ???

System is iMac 27” all-in-1 running Mavericks OSX 10.9.5 and latest Xcode 6.0.1

The App reads a binary file and writes two text files, may re-write the binary file, and draws in a window client area.

App totally runs in Xcode. App, binary file and two text files are in ~/Debug or ~/Release directory. No problem writing to files. File i/o code does this…

std::fstream out(  binary_file, std::ios::in|std::ios::binary);
if ( out )
out.read(buffer, MaxBuffer);
out.close();

ofstream info(“info_file.txt”);
if ( info.is_open() )
info << text;
info.close();
system("chmod 777 info_file.txt"); //tried this, doesn’t help

ofstream clout(“clout_file.txt”);
if ( clout.is_open() )
clout << text;
clout.close();
system("chmod 777 clout_file.txt"); //tried this, doesn’t help

App cannot write to files when run (double clicked) from Finder. Regardless of where App and files are located…

/Users/myname/Applications/Appname

/Users/myname/Library/Application Support/Appname

Other

I should say the App is Archive/Release built in Xcode and placed in destination directory for Finder situation. Is this the right way? This is my first OSX App but I’ve been programming for decades.

Permissions for Finder situation are

App: myname Read & Write, staff Read only, everyone Read only binary file: myname Read & Write, staff Read & Write, everyone Read & Write text files: myname Read & Write, staff Read & Write, everyone Read & Write

I’ve checked all the permissions in directory tree in Unix terminal also. /Users/myname/…

Xcode versus Finder, what are the differences? regarding…

user name (byname)

group name (staff, root, admin)

working directory on startup

permissions on App and files (read, write, execute)

location of App and files

would /tmp location for file writing work?

where would be the best place to put App and files?

App working directory is changed by App to be where App and files are located. Xcode -> Product -> Scheme -> Edit Scheme -> Options -> Working Directory set to same location. This doesn’t help the Finder run situation.

A MS Windows version of this App works fine. I have ported it, re-written it, for iMac OSX environment and it runs great in Xcode. What is wrong with Finder case? Why can’t files be opened in output mode?

I’m thinking of re-writing the file i/o in objective-c style but it would be a pain and should not be necessary. CString versus NSString is a big pain for me. I have had to use .mm and objective- c++ source type to get this far.

Ideas welcome and thanks.


回答1:


Full path names resolves all issues with running from Finder. Multiple directory locations were tried successfully. Awesome thanks to Paul R.



来源:https://stackoverflow.com/questions/26161144/differences-between-running-osx-app-from-finder-versus-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!