How do I make PhpED preserve line endings/breaks? - line-breaks

Professionally I work with NuSphere PhpED on a Windows computer. Whenever I open a file from an existing project and save it the IDE automatically converts all the line endings/breaks to UNIX.
This presents a problem because it means that I am unable to track my changes in SVN afterwards as it will replace the contents of the entire file instead of just the lines I have actually touched.
I have tried changing the "Default file format" settings between "Unix", "Windows" and "Autodetect"; but regardless of this setting when I open the "Save As..." dialogue "File Format:" is always listed as Unix.
Has anyone encountered this problem before and managed to overcome it?

It may be your particular NuSphere version.
On NuSphere PhpED Professional Version 14.0 (Build 14040, 64bit), when I set "Default file format" to "Windows", the "Save As" shows "File Format" of "Windows".
If I change "Default file format" to "Unix", the "Save As" shows "File Format" of "Unix".

Related

Opening text files on codeblocks

I try to debug by using cerr in c++. I know it's efficient for text editors like sublime.
But I wanted to know if there is a way i can open the output error text file on codeblocks in real time which would reflect the changes as soon as I run the program.
Right now when i do this, this happens:
Is there any way to do this efficiently,so that the file gets updated withput giving prompt each time?

Show contents of C:\Windows\System32\config using C++

I'm trying to list files of C:\Windows\System32\config directory.
I've tried to use QDir::entryList() like this
QDir dir(R"(C:\Windows\System32\config)");
dir.setFilter(QDir::Hidden | QDir::AllEntries | QDir::System | QDir::NoDotAndDotDot);
qDebug().noquote() << dir.entryInfoList();
Also I've tried to use std::filesystem::directory_iterator like this
std::string path = R"(C:\Windows\System32\config)";
for (const auto& entry : std::filesystem::directory_iterator(path))
{
qDebug().noquote() << entry.path().string().c_str();
}
Both gives me the same output:
C:\Windows\System32\config\ELAM
C:\Windows\System32\config\Journal
C:\Windows\System32\config\RegBack
C:\Windows\System32\config\systemprofile
C:\Windows\System32\config\TxR
File manager shows me this output:
C:\Windows\System32\config\BBI
C:\Windows\System32\config\BCD-Template
C:\Windows\System32\config\COMPONENTS
C:\Windows\System32\config\DEFAULT
C:\Windows\System32\config\DRIVERS
C:\Windows\System32\config\ELAM
C:\Windows\System32\config\Journal
C:\Windows\System32\config\netlogon.ftl
C:\Windows\System32\config\RegBack
C:\Windows\System32\config\SAM
C:\Windows\System32\config\SECURITY
C:\Windows\System32\config\SOFTWARE
C:\Windows\System32\config\SYSTEM
C:\Windows\System32\config\systemprofile
C:\Windows\System32\config\TxR
C:\Windows\System32\config\VSMIDK
OS: Windows 10
The question is how can I get the same output using C++?
This is likely an issue with permissions, if you view the "Security" tab in the properties window in Explorer, you will likely see some files have "Read" permission on the "Users" group, but some files only have permissions for "SYSTEM" and "Administrators".
When you run a program in Windows, even from an administrator account, it generally runs without elevation, so it won't be able to access those files with more restricted permissions.
You can explicitly run your program elevated, e.g. right click the exe/shortcut and "Run as administrator". Note that in the case of Visual Studio, you could run VS itself as administrator.
If your program will always need to run elevated, you can set it as such, in VS, on "Linker" -> "Manifest File" there is the "UAC Execution Level" option, the "highestAvailable" or "requireAdministrator" options might be useful.
If you are launching a child process, you can choose to elevate at that point, e.g. using ShellExecuteEx, which will cause a UAC popup if required.
I finally found a solution after 1 year and 9 months.
When I tried list files I was building a 32 bit app and there was Wow64 redirection. There are two ways to resolve this:
build 64 bit app
disable redirect

Visual Studio Code: can't edit LEFT-side file during COMPARE

In Visual Studio Code I open file-VS-file compare mode via:
clicking on the file A and then "Select for Compare"
clicking on the file B and then "Compare A with B"
The problem is that I can edit file B (RIGHT side), but can't edit file A (LEFT side).
Edit: this should be working out of the box in vscode version 1.41.0
It will show Unknown configuration setting but it's working.
"diffEditor.originalEditable": true
like mentioned here.
Open VSCode, open the command palette (on windows it's Ctrl + shift+ P), then type setting and open the Preferences: Open Settings (JSON)
Then you will see something like this:
Paste "diffEditor.originalEditable": true, inside the {}
Example:

Installing MinGW's gdb.exe for Code Blocks

Hey guys I really need help.
I have recently started programming C++ again and I am trying to get Code Blocks up and running but it keeps failing because of this error.
"ERROR: You need to specify a debugger program in the debuggers's settings."
Understandably this means there isn't a debugger program so I have to download one. I tried to find the gdb.exe for MinGW but I can't find it at all. I just end up with the MinGW's Installation Manager and being left confused.
Are there any tutorials about using the MinGW written for beginners or anyone willing to help?
Thanks in advance.
Steps to add gdb.exe
Open MinGW Installation Manager
select package "mingw32-gdb" from the list.
Then select "Apply Changes" in Installation menu.
This will automatically install gdb.exe in the path C:\MinGW\bin.
Please let me suggest you debugger program TDM-GCC. For download and install visit
http://wiki.codeblocks.org/index.php?title=MinGW_installation
Because a debugger program (toolchain) is very complex undertaking, is not standard in Code::Blocks. You must download it and install on Code::Blocks.
Note: It is impossible copy and paste images here. In the case linked page changes, I, or another one, should suggest new link.
However following are instructions according to images and my experience.
Download TDM-GCC from https://jmeubank.github.io/tdm-gcc/download/ click [tdm64-gcc-10.3.0-2.exe] and run it.
In Wizard Action window - Click [Create].
In Select Edition window - If MinGW/TDM (32-bit) is not checked, check it. Click [Next>].
In Licence Changes window - Click [Next>].
In New Instalation: Instalation Directory window - If text box is "C:\TDM-GCC-32", it's okay. If is not, click [Browse ...], and navigate: C:\ > TDM-GCC-32 > click [OK]. Now text box is C:\TDM-GCC-32. Click [Next>].
If a small window appears saying The directory TDM-GCC-32 is not empty! Are you sure you want to install here?. Click [Yes].
In New Installation: Download Mirror window - Click [Next>].
In New Installation: Choose Components window - Check whether Add to PATH box is checked. Actually is checked. Click [Install].
In Installing window - Wait till [Next] become black. Then click it. Even if Instalation Failed window appears click [Next].
In Completing the TDM-GCC Setup Wizard window - Click [Finish].
Go to Code Blocks > Settings > Compiler.
10a. In Global compiler settings window click "Toolchain executables". Just below, find "Compiler's installation directory". If the below text field is C:\TDM-GCC-32, it's okay. If not, click the [...] at the end of the field. In "Select directory" wizard, navigate to C:\TDM-GCC-32. Now "Folder:" should be TDM-GCC-32. Click [Select a folder] in "Select directory" wizard.
10b. In Global compiler settings. Below red "Note:..." find "Program Files" > "Debuger". If text field reads "GDB/CDB debuger : Default", it's okay, click [OK]. If not, click the down arrow at the end of the field > choose "GDB/CDB debuger : Default". Check that text field is "GDB/CDB debuger : Default". Click [OK].
Go to Code Blocks > Settings > Debugger... . In Common window, left list, click "Default". If "Executable path:"'s text field is "C:\TDM-GCC-32\bin\gdb32.exe", it's okay, click [OK]. If not, click [...] button and navigate C: > TDM-GCC-32 > bin > click gdb32 (or gdb32.exe) file > click [open] in "Select executable file" wizard. "Executable path:" should be C:\TDM-GCC-32\bin\gdb32.exe. Click [OK]. Now you can debug your program.
If Debugger does not function, close Code Blocks and restart them.
Regards.
Hey guys I suggest a better way. Download "gdb.exe" from the Internet and copy it to the below path.
C:\MinGW\Bin
It's really works. I did it.

How to launch the associated application for a file / directory / URL?

Linux seems to be easy: xdg-open <file/directory/URL>.
Apparently, Mac is similar: open should be used instead of xdg-open. I don't have access to a Mac so I couldn't test it.
For Windows, I found 4 different suggestions and those that I have tried failed.
Is there a non-java, cross platform way to launch the associated application for a certain file type?
suggests start
How to give focus to default program of shell-opened file, from Java? suggests
cmd /c start ...
How to open user system preferred editor for given file?
How to Find Out Default File Opener with Java?
suggest RUNDLL32.exe
What is the correct way to use ShellExecute() in C to open a .txt
Open file with Windows' native program within C++ code
How to use ShellExecute to open html files in Windows using C++? suggest
ShellExecute
I have tried the first 3 with system() and QProcess::startDetached() and "http://www.stackoverflow.com" as argument but they all failed; start works just fine from the command line though. I haven't tried ShellExecute yet.
What is the Windows equivalent of xdg-open? It seem to me, it is start but why did my attempts with start fail?
Is ShellExecute my only option?
EDIT I thought QDesktopServices::openUrl() was for web pages only because it did not work for files or directories.
After some debugging I figured out that if I replace \\ with / in the path on Windows, it works for files but the directories are still not opened. Any ideas what I am doing wrong?
QDir dir("C:/Documents and Settings/ali");
qDebug() << "Exists? " << dir.exists();
qDebug() << dir.absolutePath();
QDesktopServices::openUrl(QUrl(dir.absolutePath()));
qDebug() << "External app called";
Application Output:
Exists? true
"C:/Documents and Settings/ali"
External app called
But nothing happens, the directory is not opened. On Linux, directories are opened with the default file manager as expected.
SOLUTION: Due to the Qt bug and Windows quirks (malformed application window), I ended up using ShellExecute. That gives me enough flexibility to achieve exactly what I want at some expense...
Why don't you just use Qt's support for this? For example:
QDesktopServices::openUrl(QUrl("/home/realnc/test.pdf"));
This opens the document in Acrobat Reader. In general, it obeys the preferred application settings in my OS for all file types that have one or more applications associated with them. Best of all, it's platform-independent.
Edit:
The fact that it opens directories on Linux but not on Windows smells like a bug. It might be best to report this on Qt's bug tracker. In the meantime, you could have a workaround for Windows for when the file is a directory:
#ifdef Q_WS_WIN
if (QFileInfo(path).isDir())
QProcess::startDetached("explorer", QStringList(path));
else
#endif
QDesktopServices::openUrl(QUrl(path));
You can also do it with cmd.exe's start command, but you'll get an ugly terminal pop up for a few fractions of a second:
QProcess::startDetached("cmd", QStringList() << "/C" << "start"
<< QDir::toNativeSeparators(path));