Skip to content

Commit

Permalink
ecode: openURI check if scheme has been provided.
Browse files Browse the repository at this point in the history
ecode: Add portable mode.
  • Loading branch information
SpartanJ committed Dec 29, 2023
1 parent b738e95 commit ece5de2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/eepp/window/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <eepp/scene/scenemanager.hpp>
#include <eepp/system/filesystem.hpp>
#include <eepp/system/inifile.hpp>
#include <eepp/system/luapattern.hpp>
#include <eepp/system/packmanager.hpp>
#include <eepp/system/thread.hpp>
#include <eepp/system/virtualfilesystem.hpp>
Expand Down Expand Up @@ -395,6 +396,9 @@ bool Engine::openURI( const std::string& url ) {
if ( nullptr == getPlatformHelper() )
return false;

if ( !LuaPattern::matches( url, "^%w+://" ) )
return openURI( "file://" + url );

if ( String::startsWith( url, "file://" ) ) {
std::string absolutePath( FileSystem::getCurrentWorkingDirectory() );
FileSystem::dirAddSlashAtEnd( absolutePath );
Expand Down
52 changes: 49 additions & 3 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,40 @@ void App::initPluginManager() {
mPluginManager->registerPlugin( GitPlugin::Definition() );
}

std::pair<bool, std::string> App::generateConfigPath() {
if ( mPortableMode ) {
std::string path( Sys::getProcessPath() + "config" );
FileSystem::dirAddSlashAtEnd( path );
bool fileExists = FileSystem::fileExists( path );

if ( fileExists && !FileSystem::isDirectory( path ) ) {
if ( FileSystem::fileRemove( path ) )
fileExists = false;
else
return { false, Sys::getConfigPath( "ecode" ) };
}

if ( !fileExists && !FileSystem::makeDir( path ) ) {
path = Sys::getTempPath();
path += "ecode_portable";
path += FileSystem::getOSSlash();
if ( !FileSystem::fileExists( path ) && !FileSystem::makeDir( path ) )
return { false, Sys::getConfigPath( "ecode" ) };
}

return { true, path };
}

return { true, Sys::getConfigPath( "ecode" ) };
}

bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool sync,
bool stdOutLogs, bool disableFileLogs ) {
mConfigPath = Sys::getConfigPath( "ecode" );
if ( !mPortableMode )
mPortableMode = FileSystem::fileExists( Sys::getProcessPath() + "portable_mode.txt" );
auto [ok, configPath] = generateConfigPath();
mConfigPath = std::move( configPath );
mPortableModeFailed = !ok;
bool firstRun = false;
if ( !FileSystem::fileExists( mConfigPath ) ) {
FileSystem::makeDir( mConfigPath );
Expand Down Expand Up @@ -555,6 +586,16 @@ void App::onReady() {
// to run.
mPluginManager->setPluginReloadEnabled( true );
Log::info( "App Ready" );

if ( mPortableModeFailed ) {
UIMessageBox* msg = UIMessageBox::New(
UIMessageBox::OK,
i18n( "portable_mode_failed", "Portable Mode failed.\nPlease check that the "
"application directory has write permissions." ) );
msg->setTitle( "Error" );
msg->setCloseShortcut( { KEY_ESCAPE, 0 } );
msg->showWhenReady();
}
}

void App::mainLoop() {
Expand Down Expand Up @@ -3203,9 +3244,10 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe
const std::string& colorScheme, bool terminal, bool frameBuffer, bool benchmarkMode,
const std::string& css, bool health, const std::string& healthLang,
FeaturesHealth::OutputFormat healthFormat, const std::string& fileToOpen,
bool stdOutLogs, bool disableFileLogs, bool openClean ) {
bool stdOutLogs, bool disableFileLogs, bool openClean, bool portable ) {
DisplayManager* displayManager = Engine::instance()->getDisplayManager();
Display* currentDisplay = displayManager->getDisplayIndex( 0 );
mPortableMode = portable;
mDisplayDPI = currentDisplay->getDPI();
mUseFrameBuffer = frameBuffer;
mBenchmarkMode = benchmarkMode;
Expand Down Expand Up @@ -3711,6 +3753,10 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
{ "benchmark-mode" } );
args::Flag verbose( parser, "verbose", "Redirects all logs to stdout.", { 'v', "verbose" } );
args::Flag version( parser, "version", "Prints version information", { 'V', "version" } );
args::Flag portable(
parser, "portable",
"Portable Mode (it will save the configuration files within the ecode main folder)",
{ 'p', "portable" } );
args::ValueFlag<size_t> jobs(
parser, "jobs",
"Sets the number of background jobs that the application will spawn "
Expand Down Expand Up @@ -3814,7 +3860,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
prefersColorScheme ? prefersColorScheme.Get() : "", terminal.Get(), fb.Get(),
benchmarkMode.Get(), css.Get(), health || healthLang, healthLang.Get(),
healthFormat.Get(), file.Get(), verbose.Get(), disableFileLogs.Get(),
openClean.Get() );
openClean.Get(), portable.Get() );
eeSAFE_DELETE( appInstance );

Engine::destroySingleton();
Expand Down
6 changes: 5 additions & 1 deletion src/tools/ecode/ecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class App : public UICodeEditorSplitter::Client {
const std::string& colorScheme, bool terminal, bool frameBuffer, bool benchmarkMode,
const std::string& css, bool health, const std::string& healthLang,
ecode::FeaturesHealth::OutputFormat healthFormat, const std::string& fileToOpen,
bool stdOutLogs, bool disableFileLogs, bool openClean );
bool stdOutLogs, bool disableFileLogs, bool openClean, bool portable );

void createWidgetInspector();

Expand Down Expand Up @@ -430,6 +430,8 @@ class App : public UICodeEditorSplitter::Client {

void saveProject();

std::pair<bool, std::string> generateConfigPath();

protected:
std::vector<std::string> mArgs;
EE::Window::Window* mWindow{ nullptr };
Expand Down Expand Up @@ -476,6 +478,8 @@ class App : public UICodeEditorSplitter::Client {
bool mDirTreeReady{ false };
bool mUseFrameBuffer{ false };
bool mBenchmarkMode{ false };
bool mPortableMode{ false };
bool mPortableModeFailed{ false };
Time mFrameTime{ Time::Zero };
Clock mLastRender;
Clock mSecondsCounter;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/uieditor/uieditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st

createAppMenu();

mConfigPath = Sys::getConfigPath( "ecode" );
mConfigPath = Sys::getConfigPath( "eepp-uieditor" );
mColorSchemesPath = mConfigPath + "colorschemes";
auto colorSchemes(
SyntaxColorScheme::loadFromFile( mResPath + "colorschemes/colorschemes.conf" ) );
Expand Down

0 comments on commit ece5de2

Please sign in to comment.