Skip to content

Commit

Permalink
Support resource files with spaces (#197)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <louise@openrobotics.org>

Co-authored-by: Will Baker <willcbaker@gmail.com>
  • Loading branch information
chapulina and willcbaker authored Nov 21, 2020
1 parent da8f187 commit 47aa854
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
7 changes: 6 additions & 1 deletion gzbridge/ConfigLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ void ConfigLoader::_parseNodes(std::ifstream &stream, ConfigNode *parent)
}
else
{
key = newNode->getName() + ' ' + newNode->getValues().front();
key = newNode->getName();
for (auto value : newNode->getValues())
{
key += ' ' + value;
}
key.erase(std::remove(key.begin(), key.end(), '"'), key.end());
}

m_scriptList.insert(ScriptItem(key, newNode));
Expand Down
15 changes: 13 additions & 2 deletions gzbridge/OgreMaterialParser.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <iostream>
#include <sstream>

Expand Down Expand Up @@ -50,7 +51,7 @@ std::string OgreMaterialParser::GetMaterialAsJson() const
else
first = false;

std::size_t index = name.rfind(" ");
std::size_t index = name.find(" ");
if (index != std::string::npos)
{
name = name.substr(index+1);
Expand Down Expand Up @@ -150,7 +151,17 @@ std::string OgreMaterialParser::GetMaterialAsJson() const
ConfigNode *textureNode = textureUnitNode->findChild("texture");
if (textureNode)
{
std::string textureStr = textureNode->getValue(0);
std::string textureStr;
for (auto i = 0u; i < textureNode->getValues().size(); ++i)
{
textureStr += textureNode->getValue(i);
if (i + 1 != textureNode->getValues().size())
textureStr += " ";
}

textureStr.erase(std::remove(textureStr.begin(),
textureStr.end(), '"'), textureStr.end());

index = textureStr.rfind(".");
if (index != std::string::npos)
{
Expand Down
3 changes: 2 additions & 1 deletion gzbridge/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ let staticServe = function(req, res) {
if (req.url === '/')
req.url = '/index.html';

fileLoc = path.join(fileLoc, req.url);
fileLoc = unescape(path.join(fileLoc, req.url));

fs.readFile(fileLoc, function(err, data) {
if (err) {
console.error('File not found [', fileLoc, ']');
res.writeHead(404, 'Not Found');
res.write('404: File Not Found!');
return res.end();
Expand Down
11 changes: 7 additions & 4 deletions webify_models_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

path = sys.argv[1]

files = os.listdir(path)

find_cmd = ['find', path, '-name','*']
files = subprocess.check_output(find_cmd).split()
files = subprocess.check_output(find_cmd).split('\n')

for file in files:
try:
Expand Down Expand Up @@ -66,6 +64,11 @@
print sed_cmd
subprocess.check_call(sed_cmd)

# Decode whitespace
sed_cmd = ["sed", "-i", "-e", 's/%20/ /g', file]
print sed_cmd
subprocess.check_call(sed_cmd)

# find relatvie path to texture dir
texture_dir = path
if (texture_dir.find('materials/textures') == -1 and
Expand All @@ -83,7 +86,7 @@
subprocess.check_call(sed_cmd)

sed_cmd = ["sed", "-i","-e",
'/[a-zA-Z0-9_\.\/\-]\+materials\/textures/!s/\([a-zA-Z0-9_\-]\+\)\(\.png\W\)/'+ relative_path + 'materials\/textures\/\\1\\2/g', file]
'/[a-zA-Z0-9_\.\/\-]\+materials\/textures/!s/\([a-zA-Z0-9_ \-]\+\)\(\.png\W\)/'+ relative_path + 'materials\/textures\/\\1\\2/g', file]

print sed_cmd
subprocess.check_call(sed_cmd)
Expand Down

0 comments on commit 47aa854

Please sign in to comment.