Skip to content

Commit

Permalink
Merge pull request #2 from xBazilio/auto_project_creation
Browse files Browse the repository at this point in the history
Auto project creation
  • Loading branch information
xBazilio authored Dec 17, 2017
2 parents 5f36fbc + b9dd39a commit 3d217c1
Show file tree
Hide file tree
Showing 12 changed files with 697 additions and 791 deletions.
2 changes: 1 addition & 1 deletion Config/FilterPlugin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
; /Binaries/ThirdParty/*.dll
LICENSE
README.md

Templates/project.pro.user.shared.tpl
695 changes: 21 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions QtCreatorSourceCodeAccess.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 2,
"VersionName": "2.3",
"Version": 3,
"VersionName": "3.0",
"FriendlyName": "Qt Creator Source Code Access",
"Description": "Allows access to source code in Qt Creator.",
"Category": "Programming",
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ Source code accessor plugin for Unreal Editor 4, windows version. It allows to m

# Installation

1. Read Unreal Engine Wiki for [how to setup your project for use with Qt Creator](https://wiki.unrealengine.com/Using_QtCreator_With_UnrealEngine4)
1. Read Unreal Engine Wiki for [how to setup your project for use with Qt Creator](https://wiki.unrealengine.com/QtCreator_in_Windows)

## As an editor plugin
2. Download [build](https://github.com/xBazilio/UE4_Win_QtCreatorSourceCodeAccess/releases/download/2.3/QtCreatorSourceCodeAccess.zip) and put it in the `UNREAL_ENGINE_4/Plugins/Developer/QtCreatorSourceCodeAccess` folder, so that you have `QtCreatorSourceCodeAccess.uplugin` file in path `UNREAL_ENGINE_4/Plugins/Developer/QtCreatorSourceCodeAccess/QtCreatorSourceCodeAccess.uplugin`

## As a project plugin

2. Download [build](https://github.com/xBazilio/UE4_Win_QtCreatorSourceCodeAccess/releases/download/2.3/QtCreatorSourceCodeAccess.zip) or source code and put it in the `YOUR_PROJECT/Plugins/QtCreatorSourceCodeAccess` folder, so that you have `QtCreatorSourceCodeAccess.uplugin` file in path `YOUR_PROJECT/Plugins/QtCreatorSourceCodeAccess/QtCreatorSourceCodeAccess.uplugin`
3. Open your project. If it suggests to recompile the plugin - accept
## From Marketplace
2. Install free code plugin [Qt Creator Source Code Access](https://www.unrealengine.com/marketplace/qt-creator-source-code-access)

## Settings

4. Go to Settings / Plugins, find Qt Creator Source Code Access plugin under "Project / Programming" or "Installed / Programming" category and enable it if not yet, reopen project if necessary
5. Go to Edit / Editor preferences, under General / Source Code category select Qt Creator as Source Code Editor
6. (Optional) Disable Visual Studio Plugin, you do not need it any more, but you do need Visual Studio installed itself
3. Go to Settings / Plugins, find Qt Creator Source Code Access plugin under "Installed / Programming" category and enable it if not yet, reopen project if necessary
4. Go to Edit / Editor preferences, under General / Source Code category select Qt Creator as Source Code Editor
5. (Optional) Disable Visual Studio Plugin, you do not need it any more, but you do need Visual Studio installed itself

From now on you can create C++ classes and compile your project directly from Unreal Editor. Happy coding!
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/*
* Copyright (C) 2017 Vasiliy Rumyantsev
*
* This file is part of QtCreatorSourceCodeAccess, windows version.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "QtCreatorSourceCodeAccessModule.h"
#include "ModuleManager.h"
#include "Features/IModularFeatures.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/*
* Copyright (C) 2017 Vasiliy Rumyantsev
*
* This file is part of QtCreatorSourceCodeAccess, windows version.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "CoreMinimal.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#include "QtCreatorSourceCodeAccessProjectInitializer.h"
#include "DesktopPlatformModule.h"
#include "FileManagerGeneric.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
#include "Interfaces/IPluginManager.h"

#define SOLUTION_SUBPATH "Intermediate/ProjectFiles"

void FQtCreatorSourceCodeAccessProjectInitializer::InitializeProject()
{
EnginePath = FPaths::ConvertRelativePathToFull(FPaths::EngineDir());
FPaths::NormalizeDirectoryName(EnginePath);

CreateDotProFile();
CreateDefinesPriFile();
CreateIncludesPriFile();
CreateDotProDotUserFile();
}

void FQtCreatorSourceCodeAccessProjectInitializer::CreateDotProFile()
{
// iterate over solution files
class FSolutionVisitor : public IPlatformFile::FDirectoryVisitor
{
public:
TArray<FString> Headers;
TArray<FString> Sources;
const FString SolutionPath;
FSolutionVisitor(const FString SolutionPath) : SolutionPath{SolutionPath}
{
}
virtual bool Visit(const TCHAR* Filename, bool bIsDirectory)
{
if (!bIsDirectory)
{
FString StringFilename(Filename);

// skip all paths except with /Source/ substring
if (!StringFilename.Contains(TEXT("/Source/"), ESearchCase::CaseSensitive))
{
return true; // continue searching
}
// look for .cpp and .h files
// collect found files
if (StringFilename.Find(FString(".h"), ESearchCase::IgnoreCase, ESearchDir::FromEnd) == StringFilename.Len() - 2)
{
StringFilename = StringFilename.Replace(*SolutionPath, *FString("../.."), ESearchCase::CaseSensitive);
Headers.Add(StringFilename);
}
if (StringFilename.Find(FString(".cpp"), ESearchCase::IgnoreCase, ESearchDir::FromEnd) == StringFilename.Len() - 4)
{
StringFilename = StringFilename.Replace(*SolutionPath, *FString("../.."), ESearchCase::CaseSensitive);
Sources.Add(StringFilename);
}
}
return true; // continue searching
}
};
FSolutionVisitor SolutionVisitor(SolutionPath);
FFileManagerGeneric::Get().IterateDirectoryRecursively(SolutionPath.GetCharArray().GetData(), SolutionVisitor);

// create new .pro file content
FString DotProFileContent;
DotProFileContent
.Append(TEXT("TEMPLATE = app\n"))
.Append(TEXT("CONFIG += console\n"))
.Append(TEXT("CONFIG -= app_bundle\n"))
.Append(TEXT("CONFIG -= qt\n"))
.Append(TEXT("CONFIG += c++11\n"))
.Append(TEXT("\n"))
.Append(TEXT("# All the defines of your project will go in this file\n"))
.Append(TEXT("# You can put this file on your repository, but you will need to remake it once you upgrade the engine.\n"))
.Append(TEXT("include(defines.pri)\n"))
.Append(TEXT("\n"));

if (SolutionVisitor.Headers.Num())
{
DotProFileContent.Append(TEXT("HEADERS += "));
}

bool bFirstLine{true};
for (auto HeaderFile : SolutionVisitor.Headers)
{
if (bFirstLine)
{
DotProFileContent.Append(TEXT(" "));
bFirstLine = false;
}
else
{
DotProFileContent.Append(TEXT(" \\\n "));
}

DotProFileContent.Append(HeaderFile);
}

DotProFileContent.Append(TEXT("\n\n"));

if (SolutionVisitor.Sources.Num())
{
DotProFileContent.Append(TEXT("SOURCES += "));
}

bFirstLine = true;
for (auto SourceFile : SolutionVisitor.Sources)
{
if (bFirstLine)
{
DotProFileContent.Append(TEXT(" "));
bFirstLine = false;
}
else
{
DotProFileContent.Append(TEXT(" \\\n "));
}

DotProFileContent.Append(SourceFile);
}

DotProFileContent
.Append(TEXT("\n\n"))
.Append(TEXT("# All your generated includes will go in this file\n"))
.Append(TEXT("# You can not put this on the repository as this contains hardcoded paths\n"))
.Append(TEXT("# and is dependend on your windows install and engine version\n"))
.Append(TEXT("include(includes.pri)\n"));

// write new .pro file
FString DotProFilePath = FPaths::Combine(
SolutionPath,
FString(SOLUTION_SUBPATH),
FString(ProjectName).Append(TEXT(".pro"))
);
FFileHelper::SaveStringToFile(DotProFileContent, *DotProFilePath);
}

void FQtCreatorSourceCodeAccessProjectInitializer::CreateDefinesPriFile()
{
CreateDotPriFile(
FString("<NMakePreprocessorDefinitions>"),
FString("</NMakePreprocessorDefinitions>"),
FString("DEFINES"),
FPaths::Combine(
SolutionPath,
FString(SOLUTION_SUBPATH),
FString("defines.pri")
)
);
}

void FQtCreatorSourceCodeAccessProjectInitializer::CreateIncludesPriFile()
{
CreateDotPriFile(
FString("<NMakeIncludeSearchPath>"),
FString("</NMakeIncludeSearchPath>"),
FString("INCLUDEPATH"),
FPaths::Combine(
SolutionPath,
FString(SOLUTION_SUBPATH),
FString("includes.pri")
)
);
}

void FQtCreatorSourceCodeAccessProjectInitializer::CreateDotPriFile(
const FString& StartTag,
const FString& EndTag,
const FString& VarName,
const FString& FileName
)
{
FString VcxProjFilePath = FPaths::Combine(
SolutionPath,
TEXT(SOLUTION_SUBPATH),
FString(ProjectName).Append(TEXT(".vcxproj"))
);

// nothing to do here without .vcxproj file
if (!FPaths::FileExists(VcxProjFilePath)) return;

FString VcxProjFileContent;
FFileHelper::LoadFileToString(VcxProjFileContent, VcxProjFilePath.GetCharArray().GetData());

int32 StartPosition = VcxProjFileContent.Find(StartTag, ESearchCase::IgnoreCase);
if (!StartPosition)
{
// Can't continue without tag content
return;
}
else
{
StartPosition += StartTag.Len(); // shift position to the start of content
}
int32 EndPosition = VcxProjFileContent.Find(EndTag, ESearchCase::IgnoreCase);
if (!EndPosition)
{
// Can't continue without tag content
return;
}

FString ReplacementMid("\"\n");
ReplacementMid = ReplacementMid.Append(VarName).Append(TEXT(" += \""));
FString DotPriFileContent = VcxProjFileContent.Mid(StartPosition, EndPosition - StartPosition);
DotPriFileContent = DotPriFileContent.Replace(*FString(";"), *ReplacementMid);
DotPriFileContent = FString(VarName).Append(TEXT(" += \"")).Append(DotPriFileContent).Append(TEXT("\"\n"));

// write new .pri file
FFileHelper::SaveStringToFile(DotPriFileContent, *FileName);
}

void FQtCreatorSourceCodeAccessProjectInitializer::CreateDotProDotUserFile()
{
FString DotProTplPath = FPaths::Combine(
IPluginManager::Get().FindPlugin(TEXT("QtCreatorSourceCodeAccess"))->GetBaseDir(),
TEXT("Templates/project.pro.user.shared.tpl")
);

// can't continue without tpl file
if (!FPaths::FileExists(DotProTplPath)) return;

// read tpl file
FString DotProTplContent;
FFileHelper::LoadFileToString(DotProTplContent, DotProTplPath.GetCharArray().GetData());

// replace marcos to actual values
DotProTplContent = DotProTplContent.Replace(*FString("%project_name%"), *ProjectName, ESearchCase::CaseSensitive);
DotProTplContent = DotProTplContent.Replace(*FString("%project_path%"), *SolutionPath, ESearchCase::CaseSensitive);
DotProTplContent = DotProTplContent.Replace(*FString("%ue_engine_path%"), *EnginePath, ESearchCase::CaseSensitive);

// write new .pro.user.shared file
FString DotProUserSharedFilePath = FPaths::Combine(
SolutionPath,
FString(SOLUTION_SUBPATH),
FString(ProjectName).Append(TEXT(".pro.user.shared"))
);
FFileHelper::SaveStringToFile(DotProTplContent, *DotProUserSharedFilePath);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "CoreMinimal.h"

class FQtCreatorSourceCodeAccessProjectInitializer
{

public:
FQtCreatorSourceCodeAccessProjectInitializer(const FString SolutionPath, const FString ProjectName)
: SolutionPath{SolutionPath},
ProjectName{ProjectName}
{}

void InitializeProject();

private:
const FString SolutionPath;
const FString ProjectName;
FString EnginePath;

void CreateDotProFile();
void CreateDefinesPriFile();
void CreateDotPriFile(
const FString& StartTag,
const FString& EndTag,
const FString& VarName,
const FString& FileName
);
void CreateIncludesPriFile();
void CreateDotProDotUserFile();
};
Loading

0 comments on commit 3d217c1

Please sign in to comment.