コード例 #1
0
void ResourceOps::HandleNewFolder(const String& resourcePath, bool reportError)
{
    Editor* editor = GetSubsystem<Editor>();
    FileSystem* fs = GetSubsystem<FileSystem>();

    if (fs->DirExists(resourcePath) || fs->FileExists(resourcePath))
    {
        if (reportError)
        {
            String errorMsg;
            errorMsg.AppendWithFormat("Already exists:\n\n %s", resourcePath.CString());
            editor->PostModalError("New Folder Error", errorMsg);
        }

        return;
    }

    if (!fs->CreateDir(resourcePath))
    {
        if (reportError)
        {
            String errorMsg;
            errorMsg.AppendWithFormat("Could not create:\n\n %s", resourcePath.CString());
            editor->PostModalError("New Folder Error", errorMsg);
        }

        return;
    }

    // file watcher doesn't currently handle subdir
    GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh();

}
コード例 #2
0
bool ResourceOps::CheckCreate2DLevel(const String& resourcePath, const String& resourceName, bool reportError)
{

    Editor* editor = GetSubsystem<Editor>();
    Project* project = editor->GetProject();

    String fullpath = resourcePath + resourceName;
    if (!resourceName.EndsWith(".tmx"))
        fullpath += ".tmx";

    FileSystem* fs = GetSubsystem<FileSystem>();

    if (fs->FileExists(fullpath))
    {
        if (reportError)
        {
            String errorMsg;
            errorMsg.AppendWithFormat("The level:\n\n%s\n\nalready exists", fullpath.CString());
            editor->PostModalError("Create 2D Level Error", errorMsg);
        }

        return false;
    }

    return true;

}
コード例 #3
0
void ResourceOps::HandleResourceDelete(const String& resourcePath, bool reportError)
{
    Editor* editor = GetSubsystem<Editor>();
    FileSystem* fs = GetSubsystem<FileSystem>();

    if (fs->DirExists(resourcePath))
    {
        fs->RemoveDir(resourcePath, true);

        GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh();

        return;
    }
    else if (fs->FileExists(resourcePath))
    {
        if (!fs->Delete(resourcePath))
        {
            if (reportError)
            {
                String errorMsg;
                errorMsg.AppendWithFormat("Unable to delete:\n\n %s", resourcePath.CString());
                editor->PostModalError("Delete Resource Error", errorMsg);
            }

            return;
        }

        GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh();

        return;
    }
    else
    {
        if (reportError)
        {
            String errorMsg;
            errorMsg.AppendWithFormat("Unable to find:\n\n %s", resourcePath.CString());
            editor->PostModalError("Delete Resource Error", errorMsg);
        }

        return;
    }

}
コード例 #4
0
void LicenseSystem::HandleDeactivate(StringHash eventType, VariantMap& eventData)
{
    Editor* editor = GetSubsystem<Editor>();

    CurlRequest* request = (CurlRequest*) (eventData[CurlComplete::P_CURLREQUEST].GetPtr());

    if (deactivate_.NotNull())
    {
        assert(request == deactivate_);

        if (deactivate_->GetError().Length())
        {
            String msg;
            msg.AppendWithFormat("Unable to deactivate with server: %s", deactivate_->GetError().CString());
            editor->PostModalError("Deactivation Error", msg);
            LOGERROR(msg);
        }
        else
        {
            String response = request->GetResponse();
            if (response.StartsWith("AC_FAILED"))
            {
                String msg;
                msg.AppendWithFormat("Unable to deactivate with server: %s", response.CString());
                editor->PostModalError("Deactivation Error", msg);
                LOGERROR(msg);
            }
            else if (response.StartsWith("AC_NOTACTIVATED") || response.StartsWith("AC_SUCCESS"))
            {
                ResetLicense();
                RemoveLicense();

                UIModalOps* ops = GetSubsystem<UIModalOps>();
                ops->Hide();
                ops->ShowActivation();
            }

        }

        UnsubscribeFromEvents(deactivate_);
        deactivate_ = 0;
    }

}
コード例 #5
0
bool ResourceOps::CheckCreateScript(const String& resourcePath, const String& resourceName, bool reportError)
{

    Editor* editor = GetSubsystem<Editor>();
    Project* project = editor->GetProject();

    String fullpath = resourcePath + resourceName;
    if (!resourceName.EndsWith(".js"))
        fullpath += ".js";

    FileSystem* fs = GetSubsystem<FileSystem>();

    if (fs->FileExists(fullpath))
    {
        if (reportError)
        {
            String errorMsg;
            errorMsg.AppendWithFormat("The script:\n\n%s\n\nalready exists", fullpath.CString());
            editor->PostModalError("Create Script Error", errorMsg);
        }

        return false;
    }

    if (!project->IsScriptsDirOrFile(resourcePath))
    {
        if (reportError)
        {
            String errorMsg;
            errorMsg.AppendWithFormat("Scripts must reside in or in a subfolder of the Scripts folder");
            editor->PostModalError("Create Script Error", errorMsg);
        }

        return false;
    }

    return true;

}
コード例 #6
0
void ResourceOps::HandleCreate2DLevel(const String& resourcePath, const String& resourceName,
                                        bool navigateToResource, bool reportError)
{
    Editor* editor = GetSubsystem<Editor>();

    if (!CheckCreate2DLevel(resourcePath, resourceName, reportError))
        return;

    ResourceCache* cache = GetSubsystem<ResourceCache>();

    SharedPtr<File> srcFile = cache->GetFile("ClockworkEditor/templates/template_empty.tmx");
    if (srcFile.Null() || !srcFile->IsOpen())
    {
        editor->PostModalError("Create Script Error", "Could not open module template");
        return;
    }

    String fullpath = resourcePath + resourceName;
    if (!resourceName.EndsWith(".tmx"))
        fullpath += ".tmx";

    if (!CopyFile(srcFile, fullpath))
    {
        String errorMsg;
        errorMsg.AppendWithFormat("Error copying template:\n\n%s\n\nto:\n\n%s",
                                  "ClockworkEditor/template_empty.tmx", fullpath.CString());
        editor->PostModalError("Create 2D Level Error", errorMsg);
        return;
    }

    if (navigateToResource)
    {
        //ResourceFrame* rframe = GetSubsystem<MainFrame>()->GetResourceFrame();
        //rframe->EditResource(fullpath);
    }

    GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh();

}