Xcode "Building" a Project - objective-c

Honestly, I don't fully understand my question, but hopefully I can still be fairly clear about it.
I just wrote a simple project in Objective-C/Xcode. It looks like Xcode generated an executable in a folder called "Debug" and when I double-click on it, it opens a terminal window and runs fine. However, while running, it reads from a text file in the same directory that it's in. So if I want move the executable to a different location, I also have to move the text file to the same location or it won't be able to find the text file.
My question is... when I download an application on my computer (like Google Chrome or Evernote), it comes as its own file and I can place it in any directory I like; there are no associated files I have to move whenever I move the "executable". Is there a way to generate a clean application like this using Xcode?

Related

Is there a possible way to open a file in visual basic by just putting the name of the drive?

Recently I made an application that has lots of PDF files in it and I made a setup for it using Inno Setup Compiler. In the setup, I allowed people to change where they want to install the app. For opening my PDF files, I used: system.diagnostics.process.start("My pdf.pdf")
My problem is that in the code above, I put drive "C:" and when my user changed the install directory to drive "D:" the pdf's did not work and the error showed that "Cannot find the specific file". My question is that is there a way to just put the name of "computer" or "a drive" in the code above, not the specific name of the pdf, and let the computer find the file itself?
You seem to be asking for an opposite of what you actually want to achieve.
I assume you are installing files with known names. What you do not know is the directory of the files.
From your description I assume that your actual code is like:
System.Diagnostics.Process.Start("C:\My pdf.pdf")
But when the user chooses a different location (directory) for your application, the above code with a hard-coded absolute path fails.
If your application installs to the same directory as the PDFs, just use a relative path (in this case just a file name without any path). It makes an operating system look to the current working directory, which will typically be an application directory.
System.Diagnostics.Process.Start("My pdf.pdf")
Or to make it more reliable, make it explicitly look to the application directory. For that use Application.StartupPath:
System.Diagnostics.Process.Start(
System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "My pdf.pdf"))
See also Get program path in VB.NET?

Qt icons from resource file do not display

I made a user interface using Qt Designer qith Qt 5.0.1, and I used icons from a resource file. After compiling, the executable runs perfectly fine, and the icons are displayed as expected. However, when I run the programme on a different computer, they mysteriously disappear, and I am not able to get them back.
What can be the reason for this? I thought that the resources where hard-coded in the executable after compilation, but that may be wrong. In any case, I find it very peculiar that wherever I move the executable, it displays the icons on my own computer, but not on another one's.
I think you're missing some plugins. If you're using Windows and your icons are .ico type files, you need to copy the qico.dll file from the imageformats folder located somewhere in your Qt folder (something like C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats) to a subdir called imageformats that you create inside the directory that contains your deployed .exe file.

Content files showing up in install directory

So I currently have a script that works just fine with one problem. Whenever I publish it as a ClickOnce application, it has to be installed on the users computer before it can be used, and the the files I have specified to run if the user provides a valid login are showing up in the local APPDATA files.
I feel like there has to be a better way to publish my application. I want the 4 files ( a .swf that will run with flash, a bat file to run those, and a .vbs script that runs the bat file in the background so it doesn't pop up) to be included in the project, but to be written into the resulting binary files, not in their original form so the source is freely available.
Anyone have a suggestion?

Moving .lproj file inside Resources

I'm trying to begin localization on a project, and I've already got an English version of Localizable.strings going. I'm now trying to add French to that file, which is creating an fr.lproj folder, as I'd expect. However, it's putting it in my project root, and I'd like it inside my project's Resources directory.
Xcode seems to have no interest in letting me move the file, and if I move it in Finder, it goes red in Xcode as expected, but doesn't let me click to locate the file.
I've tried moving it in Finder, then editing project.pbxproj in a text editor to add Resources/ in front of the only line in there that mentions fr.lproj/Localizable.strings, and that has worked, but after doing that, the project's targets also turned red in Xcode, and building the app doesn't change that fact. Very odd.. any idea what could be going on, or how to get this going?
This can be a real pain. I even had XCode crash on me when trying to correct unwanted file locations. I found that the best way is to create the localized file (be it .strings or .xib) as a copy of the source language version outside of XCode, then drag and drop it into XCode. If you do this then XCode will display it correctly and your targets' Build Phases > Copy Bundle Resources settings will include it with its correct location. I don't know why your targets are displayed in red, perhaps you could look under Copy Bundle Resources in case anything is wrong there, or also select your project and click Validate Settings in case you haven't already done so.
Also, if you have been testing in the simulator beware of how XCode does not clean up the files in your app bundle--you may want to delete the app and run it again to make sure it's working with your new location.

Working Directory in Objective-C and Xcode: debug mode vs. executable

I am writing a program in Objective-C using Xcode. My program creates a file as follows:
[#"" writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL];
I would like the file to be created in the same directory as the executable. When I run the program from Xcode, the file is created in the debug directory as expected.
However, when I run the .app file, the file is created in the root directory. How can I get the program to create a file in the directory where the .app file is located.
Thanks a lot.
EDIT: This is a MacOS application
EDIT2: Well, it seems that I shouldn't be writing to the .app directory. Thanks bbum and Paul R. What is the proper way to do it? To be more concrete, here's what I am doing: each time the user clicks a button in the application, a piece of hardware connected to a serial port will send a bunch data which will be written to a new file. This can happen any number of times while the application is running, so numerous files may be created. I would like them all created in the same folder.
You must never make any assumptions about the initial working directory for your application, as this will depend on what method was used to launch it (e.g. Finder, Terminal (via open), Xcode, gdb, third party utility, etc). You should use an appropriate API to find a suitable directory to store temporary files or user-specific files or whatever it is you need to do. This should never be within the app's bundle and never at a path that is relative to the initial working directory.
You do not want the file to be created inside the .app wrapper. That is never the right answer; your application may easily be installed somewhere where the current user does not have write access to the YourApp.app wrapper.
(For example, my main user account is non-admin and all applications are installed admin-write-only. If an app ever fails to work because it can't write to its app wrapper, the app goes in the trash.)
See this question for an outline of where files should be stored. Depends on the role of the file.