Пример #1
0
void ProjLoad_fillProjectVarsInResourceFiles(StringTree&resourceTree, const String&templateResRoot, const String&projectResRoot, const String&subFolder,
        const String&projectName, const String&authorName, const String&projectNameAsIdentifier,
        const String&executableName, const String& productName)
{
    ArrayList<String> members = resourceTree.getMembers();

    String templateResCurrentFolder = templateResRoot + '/' + subFolder;
    String projectResCurrentFolder = projectResRoot + '/' + subFolder;

    for(int i=0; i<members.size(); i++)
    {
        String filename = members.get(i);
        String filepath = templateResCurrentFolder + '/' + filename;

        String newFilename = filename;
        ProjLoad_fillProjectVarsInString(newFilename, projectName, authorName, projectNameAsIdentifier, executableName, productName);

        String saveFile = newFilename;

        //rename file if necessary
        bool couldRename = false;
        int matchChecks = 0;
        do
        {
            couldRename = resourceTree.renameMember(filename, saveFile);
            if(!couldRename)
            {
                matchChecks++;
                saveFile = newFilename + " (" + matchChecks + ')';
            }
        }
        while (!couldRename);

        bool success = FileTools::copyFile(filepath, projectResCurrentFolder + '/' + saveFile);
        if(!success)
        {

            showSimpleMessageBox("Error creating new project", (String)"Error copying file " + filepath + " to destination " + projectResCurrentFolder + '/' + saveFile);
        }
    }

    ArrayList<String> branchNames = resourceTree.getBranchNames();

    for(int i=0; i<branchNames.size(); i++)
    {
        String branchname = branchNames.get(i);
        String branchpath = templateResCurrentFolder + '/' + branchname;

        String newBranchname = branchname;
        ProjLoad_fillProjectVarsInString(newBranchname, projectName, authorName, projectNameAsIdentifier, executableName, productName);

        String saveFolder = newBranchname;

        //rename file if necessary
        bool couldRename = false;
        int matchChecks = 0;
        do
        {
            couldRename = resourceTree.renameBranch(branchname, saveFolder);
            if(!couldRename)
            {
                matchChecks++;
                saveFolder = newBranchname + " (" + matchChecks + ')';
            }
        }
        while (!couldRename);

        bool success = FileTools::createDirectory(projectResCurrentFolder + '/' + saveFolder);
        if(success)
        {
            StringTree*tree = resourceTree.getBranch(saveFolder);
            ProjLoad_fillProjectVarsInResourceFiles(*tree, templateResRoot, projectResRoot, subFolder + '/' + saveFolder,
                                                    projectName, authorName, projectNameAsIdentifier, executableName, productName);
        }
        else
        {
            showSimpleMessageBox("Error creating new project", (String)"Error creating folder " + projectResCurrentFolder + '/' + saveFolder);
        }
    }
}
Пример #2
0
void ProjLoad_fillProjectVarsInSourceFiles(StringTree&sourceTree, const String&templateSrcRoot, const String&projectSrcRoot, const String&subFolder,
        const String&projectName, const String&authorName, const String&projectNameAsIdentifier,
        const String&executableName, const String& productName)
{
    ArrayList<String> members = sourceTree.getMembers();

    String templateSrcCurrentFolder = templateSrcRoot;
    String projectSrcCurrentFolder = projectSrcRoot;
    if(!subFolder.equals(""))
    {
        templateSrcCurrentFolder += (String)"/" + subFolder;
        projectSrcCurrentFolder += (String)"/" + subFolder;
    }

    for(int i=0; i<members.size(); i++)
    {
        String filename = members.get(i);
        String filepath = templateSrcCurrentFolder + '/' + filename;

        String fileContents;
        bool loadedFile = FileTools::loadFileIntoString(filepath, fileContents);

        if(!loadedFile)
        {
            showSimpleMessageBox("Error loading ProjectData", (String)"Error loading file " + filepath);
        }
        else
        {
            ProjLoad_fillProjectVarsInString(fileContents, projectName, authorName, projectNameAsIdentifier, executableName, productName);

            String newFilename = filename;
            ProjLoad_fillProjectVarsInString(newFilename, projectName, authorName, projectNameAsIdentifier, executableName, productName);

            String saveFile = newFilename;

            //rename file if necessary
            bool couldRename = false;
            int matchChecks = 0;
            do
            {
                couldRename = sourceTree.renameMember(filename, saveFile);
                if(!couldRename)
                {
                    matchChecks++;
                    saveFile = newFilename + " (" + matchChecks + ')';
                }
            }
            while (!couldRename);

            bool success = FileTools::writeStringToFile(projectSrcCurrentFolder + '/' + saveFile, fileContents);
            if(!success)
            {

                showSimpleMessageBox("Error creating new project", (String)"Error creating file " + projectSrcCurrentFolder + '/' + saveFile);
            }
        }
    }

    ArrayList<String> branchNames = sourceTree.getBranchNames();

    for(int i=0; i<branchNames.size(); i++)
    {
        String branchname = branchNames.get(i);
        String branchpath = templateSrcCurrentFolder + '/' + branchname;

        String newBranchname = branchname;
        ProjLoad_fillProjectVarsInString(newBranchname, projectName, authorName, projectNameAsIdentifier, executableName, productName);

        String saveFolder = newBranchname;

        //rename file if necessary
        bool couldRename = false;
        int matchChecks = 0;
        do
        {
            couldRename = sourceTree.renameBranch(branchname, saveFolder);
            if(!couldRename)
            {
                matchChecks++;
                saveFolder = newBranchname + " (" + matchChecks + ')';
            }
        }
        while (!couldRename);

        bool success = FileTools::createDirectory(projectSrcCurrentFolder + '/' + saveFolder);
        if(success)
        {
            StringTree*tree = sourceTree.getBranch(saveFolder);
            ProjLoad_fillProjectVarsInSourceFiles(*tree, templateSrcRoot, projectSrcRoot, subFolder + '/' + saveFolder,
                                                  projectName, authorName, projectNameAsIdentifier, executableName, productName);
        }
        else
        {
            showSimpleMessageBox("Error creating new project", (String)"Error creating folder " + projectSrcCurrentFolder + '/' + saveFolder);
        }
    }
}