How can I point a folder in Documents folder? - c++

How can I point a folder or file which stored in Documents folder?
So in my case that would be C:/Users/Vanya/Documents/ATFolder (AT Folder is folder I need)
What should I put instead "Vanya" to get into Documents folder, on any PC not just mine
In case it matters I'm trying to do this:
QDir().mkdir("C:/Users/%USERPROFILE%/Documents/ATFolder");
It responds as false and doesn't create folder.

Qt solution - QStandardPaths
Use QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); to get Documents directory.

Try to use std::getenv to get the value of the environment variable "USERPROFILE".
It worked for me.

Related

Access to a project subfolder

I would like to insert images in my m2doc template from an image folder in a library.
I access the library with the following query :
self.siblings().eContents(libraries::LibraryReference).library.eInverse(capellamodeller::Library)
But I can't find any folder with myLibrary.eContents() and myLibrary.ownedFolders returns null.
I also tried with myLibrary.getProject() and myLibrary.getRootContainer() but the result is the same.
Is it possible to access a subfolder in a project?
Thank you for your help,
Eva
I'm not sure how images are stored, but if the file is on the file system you can access it via its path either relative to your .genconf file or absolute.
Maybe someone on the Capella forum could give you more details about image storage in Capella libraries.

what is the proper method of using resource files in MFC project?

i have made a MFC-based game and my project includes images and sounds. Now i want to create an installer setup in order to distribute it.
i have used the resources by providing their exact path in e.g
img->Load(L"C:\\Users\\Ad33l's\\Desktop\\block mania\\block mania\\res\\db.png");
MCIWndCreate(NULL, NULL,WS_POPUP|MCIWNDF_NOPLAYBAR|MCIWNDF_NOMENU,L"C:\\Users\\Ad33l's\\Desktop\\block mania\\block mania\\res\\tick.wav");
1.Can someone tell me any way to avoid Hard-coding the actual resource path as these resource files will not be present at this same exact path in other computers ?
2.Also guide me to handle these resource files during the creation of standalone SETUP (i am using advance installer )
(as an actual answer).
Do not use absolute path, always use relative path; relative to your EXE file is one solution.
The EXE path can be found using GetModuleFileName.
char appPath[MAXFILENAMELEN];
GetModuleFileName(NULL, appPath, MAXFILENAMELEN);
(addendum) appPath name is misleading, it contains the full name of the application; you need to extract the path from the full application name.
We do something like this:
(edit to make it compilable in unicode)
TCHAR applicationPath[MAX_PATH];
GetModuleFileName(NULL, applicationPath, MAX_PATH);
CString sSoundFile(applicationPath);
PathRemoveFileSpec(sSoundFile.GetBuffer());
sSoundFile.ReleaseBuffer();
From there, you can do something like (pseudocode-ish):
img.Load( appPath + "//Images//db.png" );
You can have a variable that saves the directory they want to install your program in. After they choose the directory they want to install it in, go off of that. Or you can also use system folders like the appdata folder
A first solution would be to configure your setup project to install the installation files under the DesktopFolder\block mania\block mania\res. Then, you can access within your application the current user Desktop location and append to it the remaining fix location (block mania\block mania\res).
Another solution would be to configure the setup project to create registries at install time which will store the paths of the installation files. Then, your application could read the installation paths from registry.
Finally you could also create at install time environment variables containing the paths of the installation file and, then use within your application the environment variables to access the installed files locations.

Installing OpenCart extensions locally

When installing OpenCart extensions, you´re generally given a bunch of folders that should be copied to the root directory and the extension files will find their way to the right subfolders. This works great in FTP software, but on a local installation (Mac OSX) using Finder, this operation makes Finder want to overwrite the folders completely, deleting the actual site and just keep the extension.
I can hold Alt when dragging the folders and it will give me the option to not overwrite, the problem is I have hidden files visible, which means there's now a .DS_STORE file in each folder and the ”Hold ALT”-approach doesn’t work in case there are ANY duplicate files in any of the folders.
I’m sure someone out there has stumbled upon the same problem, any ideas for how to solve such a simple but annoying problem? I do not wish to use FTP software for local file management.
I have the same problem, and i found 3 different ways to solve this:
a - use another file manager, i personally use "Transmit" to do this sort of things;
b - use terminal, like: ditto <source> <destination>. Or easier way just type ditto, and drag the source folder, then drag the destination folder, all inside source will merge inside destination;
c - unzip the plugin, inside the OC folder using the terminal, like: tar -zxvf plugin.zip;

Django tutorial path: TEMPLATE_PATH dir on a Mac networked computer

I'm (slowly!) working my way through the Django tutorial, and I've reached the point in Part 2 where I'm supposed to set the template_dir. I'm on a Mac (at work) where my user profile resides on a server, and I can't figure out how to set the path.
The tutorial files are in a folder called "tutorialshell", inside a folder called "Django," which is a first-level file inside my user folder "mattshepherd". That folder is the native folder when I launch the Terminal, for instance: it always starts me inside "mattshepherd".
I've tried
"~/Django/tutorialshell/templates"
and
"home/Django/tutorialshell/templates"
with no luck so far. I imagine there's some trick to doing this, as the files I'm trying to link to are on the network drive in my user folder, not on my local hard drive. Advice?
You want the absolute, not relative path. If you go to ~/Django/tutorialshell/templates in your terminal and then type pwd, it will tell you the full path to that folder. That's the value you should enter for the path.
Also: I assume you're actually talking about TEMPLATE_DIRS? If so, keep in mind that it's a list of paths, so it should look like:
TEMPLATE_DIRS = (
"/path/to/Django/tutorialshell/templates", # don't forget that trailing comma!
)
/Users/mattshepherd/Django/tutorialshell/templates
Please keep in mind that there is a LIST of template directories as mentioned by Jordan. The above location should work. In mac the user home directories are located at /Users/ + yourusername
It might be /home/ if /Users/ does not work.
As others have said you need the absolute path. But i would really suggest you to use relative path. It will make your code much more flexible. There are many ways to do it, this is what i usually do:
import os
ROOT = os.path.abspath(os.path.dirname(__file__))
then for the templates just do:
os.path.join(ROOT, 'templates')
You said you are using a Mac but you can make your code even more flexible by replacing "//" with "/" in the case you are using windows.

Excluding a single project file from an SVN repository

I have a django project that I have been working on as a solo developer, and have been using TortoiseSVN to keep the code managed in a repository on a work server. I work on this on a local installation of django etc.
There is now a second person who will be working on this project, and the possibility of working on some other PCs.
Now, there should, for the time being, only be one development version (branch?) of this project, but the configuration file (settings.py) will need to be different on each computer that is being used. I want to create one local version of this file on each PC which should not need to be changed again.
How can I set the repository (preferably within TortoiseSVN) to exclude this one file? E.g. the repository should not include settings.py. When a checkout occurs, it should update all files in the local folder but not change/remove the local copy of settings.py. When a commit occurs, settings.py should be ignored and not uploaded.
At the moment settings.py is overwritten/updated as per any other file in the project folder/repository.
Any nudges in the right direction would be useful - I'm new to SVN generally and would like to know if this is something that's going to need detailed understanding of branching or if there is a simpler way.
Thanks
In TortoiseSVN, when you try to commit your files, in the file list dialog, right click the file and look for the Ignore option. You can ignore by complete filename or extension.
If the file is already in the repository, and you want to remove it from there and ignore it, you can simply right-click the file and in the TortoiseSVN menu look for the 'Delete and add to ignore list' option.
You'll be looking for the svn:ignore property, which tells subversion to not version files matching a pattern or patterns you specify.
There's some guidance on using it with TortoiseSVN at:
http://arcware.net/tortoisesvn-global-ignore-pattern-vs-svn-ignore/
These should help:
I have a file in my project that every developer must change, but I don't want those local mods to ever be committed. How can I make 'svn commit' ignore the file?
Excluding Items from the Commit List
The typical solution is to do what bgever said and ignore the settings file itself, and then commit a file with example values, something like settings.py.example. That file should only be updated when you add or remove settings. When deploying, you'd copy that to settings.py and edit the values.