1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

A Whole New World (clang-format edition)

I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?

I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon

A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format

A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
This commit is contained in:
Rémi Verschelde
2017-03-05 16:44:50 +01:00
parent 45438e9918
commit 5dbf1809c6
1318 changed files with 140051 additions and 166004 deletions

View File

@@ -32,10 +32,10 @@
#include "os/memory.h"
#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include "print_string.h"
#include <stdio.h>
#include <wchar.h>
#include <windows.h>
/*
@@ -61,36 +61,32 @@ struct DirAccessWindowsPrivate {
Error DirAccessWindows::list_dir_begin() {
_cisdir=false;
_cishidden=false;
_cisdir = false;
_cishidden = false;
list_dir_end();
p->h = FindFirstFileExW((current_dir+"\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
return (p->h==INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
}
String DirAccessWindows::get_next() {
if (p->h==INVALID_HANDLE_VALUE)
if (p->h == INVALID_HANDLE_VALUE)
return "";
_cisdir = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
_cishidden = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
_cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
_cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
String name=p->fu.cFileName;
String name = p->fu.cFileName;
if (FindNextFileW(p->h, &p->fu) == 0) {
FindClose(p->h);
p->h=INVALID_HANDLE_VALUE;
p->h = INVALID_HANDLE_VALUE;
}
return name;
}
bool DirAccessWindows::current_is_dir() const {
@@ -105,65 +101,60 @@ bool DirAccessWindows::current_is_hidden() const {
void DirAccessWindows::list_dir_end() {
if (p->h!=INVALID_HANDLE_VALUE) {
if (p->h != INVALID_HANDLE_VALUE) {
FindClose(p->h);
p->h=INVALID_HANDLE_VALUE;
p->h = INVALID_HANDLE_VALUE;
}
}
int DirAccessWindows::get_drive_count() {
return drive_count;
}
String DirAccessWindows::get_drive(int p_drive) {
if (p_drive<0 || p_drive>=drive_count)
if (p_drive < 0 || p_drive >= drive_count)
return "";
return String::chr(drives[p_drive])+":";
return String::chr(drives[p_drive]) + ":";
}
Error DirAccessWindows::change_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
p_dir=fix_path(p_dir);
p_dir = fix_path(p_dir);
wchar_t real_current_dir_name[2048];
GetCurrentDirectoryW(2048,real_current_dir_name);
String prev_dir=real_current_dir_name;
GetCurrentDirectoryW(2048, real_current_dir_name);
String prev_dir = real_current_dir_name;
SetCurrentDirectoryW(current_dir.c_str());
bool worked=(SetCurrentDirectoryW(p_dir.c_str())!=0);
bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
String base = _get_root_path();
if (base!="") {
if (base != "") {
GetCurrentDirectoryW(2048,real_current_dir_name);
GetCurrentDirectoryW(2048, real_current_dir_name);
String new_dir;
new_dir = String(real_current_dir_name).replace("\\","/");
new_dir = String(real_current_dir_name).replace("\\", "/");
if (!new_dir.begins_with(base)) {
worked=false;
worked = false;
}
}
if (worked) {
GetCurrentDirectoryW(2048,real_current_dir_name);
current_dir=real_current_dir_name; // TODO, utf8 parser
current_dir=current_dir.replace("\\","/");
GetCurrentDirectoryW(2048, real_current_dir_name);
current_dir = real_current_dir_name; // TODO, utf8 parser
current_dir = current_dir.replace("\\", "/");
} //else {
SetCurrentDirectoryW(prev_dir.c_str());
SetCurrentDirectoryW(prev_dir.c_str());
//}
return worked?OK:ERR_INVALID_PARAMETER;
return worked ? OK : ERR_INVALID_PARAMETER;
}
Error DirAccessWindows::make_dir(String p_dir) {
@@ -171,18 +162,18 @@ Error DirAccessWindows::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
p_dir=get_current_dir().plus_file(p_dir);
p_dir = get_current_dir().plus_file(p_dir);
p_dir=fix_path(p_dir);
p_dir = p_dir.replace("/","\\");
p_dir = fix_path(p_dir);
p_dir = p_dir.replace("/", "\\");
bool success;
int err;
p_dir="\\\\?\\"+p_dir; //done according to
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
p_dir = "\\\\?\\" + p_dir; //done according to
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
success=CreateDirectoryW(p_dir.c_str(), NULL);
success = CreateDirectoryW(p_dir.c_str(), NULL);
err = GetLastError();
if (success) {
@@ -196,21 +187,18 @@ Error DirAccessWindows::make_dir(String p_dir) {
return ERR_CANT_CREATE;
}
String DirAccessWindows::get_current_dir() {
String base = _get_root_path();
if (base!="") {
if (base != "") {
String bd = current_dir.replace("\\","/").replace_first(base,"");
String bd = current_dir.replace("\\", "/").replace_first(base, "");
if (bd.begins_with("/"))
return _get_root_string()+bd.substr(1,bd.length());
return _get_root_string() + bd.substr(1, bd.length());
else
return _get_root_string()+bd;
return _get_root_string() + bd;
} else {
}
return current_dir;
@@ -221,9 +209,9 @@ bool DirAccessWindows::file_exists(String p_file) {
GLOBAL_LOCK_FUNCTION
if (!p_file.is_abs_path())
p_file=get_current_dir().plus_file(p_file);
p_file = get_current_dir().plus_file(p_file);
p_file=fix_path(p_file);
p_file = fix_path(p_file);
//p_file.replace("/","\\");
@@ -235,7 +223,7 @@ bool DirAccessWindows::file_exists(String p_file) {
if (INVALID_FILE_ATTRIBUTES == fileAttr)
return false;
return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY);
return !(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
bool DirAccessWindows::dir_exists(String p_dir) {
@@ -243,34 +231,33 @@ bool DirAccessWindows::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
p_dir=get_current_dir().plus_file(p_dir);
p_dir = get_current_dir().plus_file(p_dir);
p_dir=fix_path(p_dir);
p_dir = fix_path(p_dir);
//p_dir.replace("/","\\");
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
DWORD fileAttr;
fileAttr = GetFileAttributesW(p_dir.c_str());
if (INVALID_FILE_ATTRIBUTES == fileAttr)
return false;
return (fileAttr&FILE_ATTRIBUTE_DIRECTORY);
return false;
return (fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
Error DirAccessWindows::rename(String p_path,String p_new_path) {
Error DirAccessWindows::rename(String p_path, String p_new_path) {
if (p_path.is_rel_path())
p_path=get_current_dir().plus_file(p_path);
p_path = get_current_dir().plus_file(p_path);
p_path=fix_path(p_path);
p_path = fix_path(p_path);
if (p_new_path.is_rel_path())
p_new_path=get_current_dir().plus_file(p_new_path);
p_new_path = get_current_dir().plus_file(p_new_path);
p_new_path=fix_path(p_new_path);
p_new_path = fix_path(p_new_path);
if (file_exists(p_new_path)) {
if (remove(p_new_path) != OK) {
@@ -278,18 +265,17 @@ Error DirAccessWindows::rename(String p_path,String p_new_path) {
};
};
return ::_wrename(p_path.c_str(),p_new_path.c_str())==0?OK:FAILED;
return ::_wrename(p_path.c_str(), p_new_path.c_str()) == 0 ? OK : FAILED;
}
Error DirAccessWindows::remove(String p_path) {
Error DirAccessWindows::remove(String p_path) {
if (p_path.is_rel_path())
p_path=get_current_dir().plus_file(p_path);
p_path = get_current_dir().plus_file(p_path);
p_path=fix_path(p_path);
p_path = fix_path(p_path);
printf("erasing %s\n",p_path.utf8().get_data());
printf("erasing %s\n", p_path.utf8().get_data());
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
//DWORD fileAttr = GetFileAttributesExW(p_path.c_str(), GetFileExInfoStandard, &fileInfo);
@@ -297,11 +283,11 @@ Error DirAccessWindows::remove(String p_path) {
fileAttr = GetFileAttributesW(p_path.c_str());
if (INVALID_FILE_ATTRIBUTES == fileAttr)
return FAILED;
if ((fileAttr&FILE_ATTRIBUTE_DIRECTORY))
return ::_wrmdir(p_path.c_str())==0?OK:FAILED;
return FAILED;
if ((fileAttr & FILE_ATTRIBUTE_DIRECTORY))
return ::_wrmdir(p_path.c_str()) == 0 ? OK : FAILED;
else
return ::_wunlink(p_path.c_str())==0?OK:FAILED;
return ::_wunlink(p_path.c_str()) == 0 ? OK : FAILED;
}
/*
@@ -331,10 +317,10 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const {
return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_
}
*/
size_t DirAccessWindows::get_space_left() {
size_t DirAccessWindows::get_space_left() {
uint64_t bytes = 0;
if (!GetDiskFreeSpaceEx(NULL,(PULARGE_INTEGER)&bytes,NULL,NULL))
if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL))
return 0;
//this is either 0 or a value in bytes.
@@ -343,26 +329,25 @@ size_t DirAccessWindows::get_space_left() {
DirAccessWindows::DirAccessWindows() {
p = memnew( DirAccessWindowsPrivate );
p->h=INVALID_HANDLE_VALUE;
current_dir=".";
p = memnew(DirAccessWindowsPrivate);
p->h = INVALID_HANDLE_VALUE;
current_dir = ".";
drive_count=0;
drive_count = 0;
#ifdef UWP_ENABLED
Windows::Storage::StorageFolder ^install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
Windows::Storage::StorageFolder ^ install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
change_dir(install_folder->Path->Data());
#else
DWORD mask = GetLogicalDrives();
DWORD mask=GetLogicalDrives();
for (int i = 0; i < MAX_DRIVES; i++) {
for (int i=0;i<MAX_DRIVES;i++) {
if (mask & (1 << i)) { //DRIVE EXISTS
if (mask&(1<<i)) { //DRIVE EXISTS
drives[drive_count]='a'+i;
drives[drive_count] = 'a' + i;
drive_count++;
}
}
@@ -371,10 +356,9 @@ DirAccessWindows::DirAccessWindows() {
#endif
}
DirAccessWindows::~DirAccessWindows() {
memdelete( p );
memdelete(p);
}
#endif //windows DirAccess support