ewol/ewol_tutorial_file_access.html

228 lines
18 KiB
HTML

<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- For Mobile Devices -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<title>Ewol: Ewol Widget in OpenGl: EWOL: File access</title>
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="doxy-boot.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">Ewol: Ewol Widget in OpenGl 0.10.0</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Main&nbsp;Page</a></li>
<li><a href="pages.html">Related&nbsp;Pages</a></li>
<li><a href="namespaces.html">Namespaces</a></li>
<li><a href="annotated.html">Classes</a></li>
<li><a href="files.html">Files</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Link-libs<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
<li><a href="http://atria-soft.github.io/echrono">echrono</a></li>
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
<li><a href="http://atria-soft.github.io/etranslate">etranslate</a></li>
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
<li><a href="http://musicdsp.github.io/audio-ess">audio-ess</a></li>
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
</ul>
</li>
</ul>
<div id="search-box" class="input-group">
<div class="input-group-btn">
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-search"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">All</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Namespaces</a></li>
<li><a href="#">Files</a></li>
<li><a href="#">Functions</a></li>
<li><a href="#">Variables</a></li>
<li><a href="#">Typedefs</a></li>
<li><a href="#">Enumerations</a></li>
<li><a href="#">Enumerator</a></li>
<li><a href="#">Friends</a></li>
<li><a href="#">Macros</a></li>
<li><a href="#">Pages</a></li>
</ul>
</div>
<button id="search-close" type="button" class="close" aria-label="Close">
<span aria-hidden="true"></span>
</button>
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div class="content" id="content">
<div class="container">
<div class="row">
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
<div style="margin-bottom: 15px;margin-top: 60px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">EWOL: File access </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#ewol_tutorial_file_access_objectifs">Objectifs: </a></li>
<li class="level1"><a href="#ewol_tutorial_file_access_limit">Limitation </a></li>
<li class="level1"><a href="#ewol_tutorial_file_access_property">Generic Properties </a></li>
<li class="level1"><a href="#ewol_tutorial_file_access_package">Integrate a file in a package </a></li>
<li class="level1"><a href="#ewol_tutorial_file_access_read">Read a file </a></li>
<li class="level1"><a href="#ewol_tutorial_file_access_write">Write a file </a></li>
<li class="level1"><a href="#ewol_tutorial_file_access_theme">&#39;Theme&#39; management: </a></li>
</ul>
</div>
<div class="textblock"><h1><a class="anchor" id="ewol_tutorial_file_access_objectifs"></a>
Objectifs: </h1>
<ul>
<li>Understand why we wrap interface on file system</li>
<li>read and write files</li>
</ul>
<h1><a class="anchor" id="ewol_tutorial_file_access_limit"></a>
Limitation </h1>
<p>Application generation is really simple, but package management can create some problems...</p>
<p>For example :</p><ul>
<li>Android does not permit access on the file system, but we need data that is named assets, these data in contained in a zip file.</li>
<li>Linux set his own application data in a special path : /usr/shared/applName/</li>
<li>MacOs create a bundle (*.app) that is a folder with all application data.</li>
<li>...</li>
</ul>
<p>For all these reasons we need to wrap standard application interface. (you can acces directly but it could be tricky and depend on the target)</p>
<h1><a class="anchor" id="ewol_tutorial_file_access_property"></a>
Generic Properties </h1>
<p>By default we dertermine some basics for files.</p>
<p>Then we need to determine file in the tree with:</p><ul>
<li>**"DATA:XXX"** Application internal data<ul>
<li>Linux: /usr/share/applName/</li>
<li>Android: /xxx/yyy/applName.apk/asssets/</li>
<li>IOs: applName.app/share</li>
<li>MacOs: applName.app/Resources</li>
</ul>
</li>
<li>**"USERDATA:XXX"** User save data (like game save)<ul>
<li>Linux: ~/.local/share/applName/</li>
<li>Android: /xxx/yyy/data/applName/</li>
</ul>
</li>
<li>**"HOME:XXX"** User home folder<ul>
<li>Linux: ~/</li>
<li>Android: /sdcard/</li>
<li>IOs: &mdash; =&gt; no Home</li>
<li>MacOs: ~/</li>
</ul>
</li>
<li>**"/XXX"** Direct acces on a file in the fileSystem</li>
<li>...</li>
</ul>
<p>When you will call a file, you need to just call it with the starting name.</p>
<p>For example if I want to access at an application data I will call the file : "DATA:myImage.png"</p>
<h1><a class="anchor" id="ewol_tutorial_file_access_package"></a>
Integrate a file in a package </h1>
<p>In your <code>lutin_xxx.py</code> file add:</p>
<div class="fragment"><div class="line"><span class="comment"># to copy a single file:</span></div><div class="line">myModule.copy_file(<span class="stringliteral">&quot;relative/path/file.svg&quot;</span>,<span class="stringliteral">&quot;destination/folder/fileNewName.svg&quot;</span>)</div><div class="line"><span class="comment"># to copy an entire patern path</span></div><div class="line">myModule.copy_path(<span class="stringliteral">&quot;relative/path/start*.png&quot;</span>,<span class="stringliteral">&quot;destination/folder/&quot;</span>)</div></div><!-- fragment --><p>And now you can acces on these file with : "DATA:destination/folder/fileNewName.svg"</p>
<h1><a class="anchor" id="ewol_tutorial_file_access_read"></a>
Read a file </h1>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/__f__s__node__8hpp.html">etk/os/FSNode.hpp</a>&gt;</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">etk::FSNode file(<span class="stringliteral">&quot;DATA:destination/folder/file.svg&quot;</span>);</div><div class="line"><span class="keywordflow">if</span> (file.exist() == <span class="keyword">false</span>) {</div><div class="line"> APPL_ERROR(<span class="stringliteral">&quot;Can not read the file (Does not exist)&quot;</span>);</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line">APPL_INFO(<span class="stringliteral">&quot;open :&quot;</span> &lt;&lt; file &lt;&lt; <span class="stringliteral">&quot; with size=&quot;</span> &lt;&lt; file.fileSize());</div><div class="line"><span class="keywordflow">if</span> (file.fileOpenRead() == <span class="keyword">false</span>) {</div><div class="line"> APPL_ERROR(<span class="stringliteral">&quot;Can not open in read mode the file: &quot;</span> &lt;&lt; file);</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"><span class="comment">// get a char</span></div><div class="line">APPL_INFO(<span class="stringliteral">&quot;read in: &quot;</span> &lt;&lt; file &lt;&lt; <span class="stringliteral">&quot; the first char=&#39;&quot;</span> &lt;&lt; file.fileGet() &lt;&lt; <span class="stringliteral">&quot;&#39;&quot;</span>);</div><div class="line"><span class="comment">// Get a line</span></div><div class="line">std::string output;</div><div class="line">file.fileGets(output);</div><div class="line">APPL_INFO(<span class="stringliteral">&quot;and the end of the line =&#39;&quot;</span> &lt;&lt; output &lt;&lt; <span class="stringliteral">&quot;&#39;&quot;</span>);</div><div class="line"><span class="comment">// close the file (note : if you did not do it, it will be close automaticly with an error)</span></div><div class="line">file.fileClose();</div></div><!-- fragment --><h1><a class="anchor" id="ewol_tutorial_file_access_write"></a>
Write a file </h1>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/__f__s__node__8hpp.html">etk/os/FSNode.hpp</a>&gt;</span></div><div class="line"></div><div class="line">...</div><div class="line"></div><div class="line">etk::FSNode file(<span class="stringliteral">&quot;USERDATA:exmple.txt&quot;</span>);</div><div class="line">APPL_INFO(<span class="stringliteral">&quot;open :&quot;</span> &lt;&lt; file);</div><div class="line"><span class="keywordflow">if</span> (file.fileOpenWrite() == <span class="keyword">false</span>) {</div><div class="line"> APPL_ERROR(<span class="stringliteral">&quot;Can not open in write mode the file: &quot;</span> &lt;&lt; file);</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"><span class="comment">// put a char</span></div><div class="line">file.filePut(<span class="charliteral">&#39;A&#39;</span>);</div><div class="line"><span class="comment">// write a line</span></div><div class="line">file.filePuts(<span class="stringliteral">&quot; other string to put in the file ... \n&quot;</span>);</div><div class="line"><span class="comment">// close the file (note : if you did not do it, it will be close automaticly with an error)</span></div><div class="line">file.fileClose();</div></div><!-- fragment --><h1><a class="anchor" id="ewol_tutorial_file_access_theme"></a>
'Theme' management: </h1>
<p>The theme management is a subset of a file selected by a main key. For example the basic theme of an API can be manage with only 2 commands (set the theme, and request upate of GUI)</p>
<p>At the start of the program, you might specify the default path theme:</p>
<div class="fragment"><div class="line">etk::theme::setNameDefault(<span class="stringliteral">&quot;GUI_COLOR&quot;</span>, <span class="stringliteral">&quot;theme/black&quot;</span>);</div><div class="line">etk::theme::setNameDefault(<span class="stringliteral">&quot;GUI_SHAPE&quot;</span>, <span class="stringliteral">&quot;theme/rounded&quot;</span>);</div></div><!-- fragment --><p>And when you want to change the theme, just call:</p>
<div class="fragment"><div class="line"><span class="comment">// change the theme :</span></div><div class="line">etk::theme::setName(<span class="stringliteral">&quot;GUI_COLOR&quot;</span>, <span class="stringliteral">&quot;theme/white&quot;</span>);</div><div class="line"><span class="comment">// force reload of all the resources :</span></div><div class="line"><a class="code" href="_context_8hpp.html#a32db0d1e16baf02f1edf72bebd3b90e0">ewol::getContext</a>().getResourcesManager().reLoadResources();</div><div class="line"><a class="code" href="_context_8hpp.html#a32db0d1e16baf02f1edf72bebd3b90e0">ewol::getContext</a>().<a class="code" href="classewol_1_1_context.html#a1e7471105949c1acfd37c7a13a74e021">forceRedrawAll</a>();</div></div><!-- fragment --><p><b>Note:</b></p>
<div class="fragment"><div class="line">This is not done automaticly, because reloading the resources can have a real cost of time.</div></div><!-- fragment --><p>You can acces on your theme with accessing the filename: "THEME:GUI_COLOR:your/sub/path/file.xx"</p>
<p>An important think is that the theme file is searching in many path in the order:</p><ul>
<li>USERDATA:GUI_COLOR:your/sub/path/file.xx</li>
<li>DATA:GUI_COLOR:your/sub/path/file.xx</li>
<li>USERDATA:GUI_COLOR(default):your/sub/path/file.xx</li>
<li>DATA:GUI_COLOR(default):your/sub/path/file.xx</li>
</ul>
<p>Like this a user can overload the application theme... </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated on Mon Oct 24 2016 15:35:52 for Ewol: Ewol Widget in OpenGl by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.12
</small></address>
</body>
</html>