﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=%E5%88%A9%E7%94%A8%E8%80%85%3AGsrb3d%2FAccessing_Files</id>
	<title>利用者:Gsrb3d/Accessing Files - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=%E5%88%A9%E7%94%A8%E8%80%85%3AGsrb3d%2FAccessing_Files"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Gsrb3d/Accessing_Files&amp;action=history"/>
	<updated>2026-06-02T11:43:52Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Gsrb3d/Accessing_Files&amp;diff=96847&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Gsrb3d/Accessing_Files&amp;diff=96847&amp;oldid=prev"/>
		<updated>2018-06-28T18:47:32Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 18:47時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Gsrb3d/Accessing_Files&amp;diff=96846&amp;oldid=prev</id>
		<title>wiki&gt;Gsrb3d: /* Developers' PoV */ Add comments to code</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Gsrb3d/Accessing_Files&amp;diff=96846&amp;oldid=prev"/>
		<updated>2010-04-06T00:54:06Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Developers&amp;#039; PoV: &lt;/span&gt; Add comments to code&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The purpose of this page is to document the on going changes to&lt;br /&gt;
accessing files methods from inside Blender, in a multi OS, multi&lt;br /&gt;
user capable way. The most visible (side) effect would be a&lt;br /&gt;
reorganization of where files go (user default scene, user&lt;br /&gt;
scripts, shared plugins, etc) for users and some changes in code&lt;br /&gt;
for programmers. And it will not only cover config files, but all&lt;br /&gt;
files can (and should) be handled by it.&lt;br /&gt;
&lt;br /&gt;
At first this can sound like adding complexity, but it is the&lt;br /&gt;
other way around, it makes all files equal and simplifies code by&lt;br /&gt;
centralizing it. No more &amp;quot;new file incomplete and previous&lt;br /&gt;
version lost&amp;quot; because the quota was exceeded, no matter if it was&lt;br /&gt;
a config file or a .blend, eg. It is the parallel of ''malloc()''&lt;br /&gt;
vs ''MEM_mallocN()''.&lt;br /&gt;
&lt;br /&gt;
Another new thing is the use of Enviroment Variables internally to&lt;br /&gt;
provide easy storage of some information, plus easy integration with&lt;br /&gt;
other tools to cover the needs of advanced users, for example in&lt;br /&gt;
renderfarms. Normal users will not notice anything different than&lt;br /&gt;
before.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Classes of Files=&lt;br /&gt;
&lt;br /&gt;
Some basic types to handle:&lt;br /&gt;
&lt;br /&gt;
; Shared files&lt;br /&gt;
: All files that are installed and that users will use, but must not written by them. Or in other words, the default data that is not the executable file. No coder should care if global install or &amp;quot;unpack and run&amp;quot;, the point is they are defaults, shared by everyone for reading.&lt;br /&gt;
&lt;br /&gt;
; User files&lt;br /&gt;
: User configuration files, overriding Shared files. The structure of directories mimics the Shared files.&lt;br /&gt;
&lt;br /&gt;
; Temporary files&lt;br /&gt;
: Files that are needed for some time, but can be removed later. Typical place will be in local harddisk, not using disk quota, but not allowing others to overwrite. For example files used to communicate with external render engines.&lt;br /&gt;
&lt;br /&gt;
; Normal files&lt;br /&gt;
: Other type of files not covered by above types, but which would benefit from the common file access API, specially for such features as backups or error checking.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Config File Layout=&lt;br /&gt;
&lt;br /&gt;
Shared and User files share internal layout by default, they differ in&lt;br /&gt;
the leading path. Those base paths are determined in a per OS basis,&lt;br /&gt;
via special calls ''GHOST_getSystemDir()'' and&lt;br /&gt;
''GHOST_getUserDir()''. The reason to use GHOST is not arbitrary, it&lt;br /&gt;
allows MacOSX to use Cocoa calls without problems, for example.&lt;br /&gt;
&lt;br /&gt;
The ''getSystemDir'' will support &amp;quot;unpack and run&amp;quot; (where the binary&lt;br /&gt;
is) as well as proper install style path. It can do checks to detect&lt;br /&gt;
which is the case or be hardcoded at compile time. It can always be&lt;br /&gt;
overriden with ''BLENDER_SHARE'' env var. The ''getUserDir'' will&lt;br /&gt;
figure where the user config is to be stored (checking LDAP, env var&lt;br /&gt;
''HOME'' or whichever method applies in the OS).&lt;br /&gt;
&lt;br /&gt;
Possible values for system dir:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 /some/where/blender-2.56-linux-glibc236-py31-i386/ # &amp;quot;unpack and run&amp;quot;&lt;br /&gt;
 /usr/share/blender/&lt;br /&gt;
 /Library/Application Support/Blender/&lt;br /&gt;
 # MSWindows example needed&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Possible values for user dir:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 /home/USERNAME/.blender/&lt;br /&gt;
 /Users/USERNAME/Library/Application Support/Blender/&lt;br /&gt;
 c:\Documents and Settings\USERNAME\Application Data\Blender Fundation\Blender\Configuration\&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The examples above are what the GHOST calls can return, not what they&lt;br /&gt;
have to return. If the OS uses translated paths&lt;br /&gt;
(''c:\Dokumente und Einstellungen\...'')&lt;br /&gt;
or administrator made a different layout (alpha classification&lt;br /&gt;
''/home/a/aUSERNAME'', ''/home/b/bUSERNAME'' ...) the values will&lt;br /&gt;
vary. What matters is that the calls return the place where to start.&lt;br /&gt;
&lt;br /&gt;
If in any OS it is desired, the user dir can reside in the same place&lt;br /&gt;
than system dir or a child of it, for example for &amp;quot;unpack and run&amp;quot;. In&lt;br /&gt;
Unix it is not the norm, and in any OS user dir is only needed to&lt;br /&gt;
write changed or new files at run time, so unifiying the places are&lt;br /&gt;
only strongly recommended for border cases like &amp;quot;unpack and run from&lt;br /&gt;
thumbdrive&amp;quot;. Other cases should be fine using the real user directory,&lt;br /&gt;
as otherwise it makes impossible to share that &amp;quot;unpack and run&amp;quot;&lt;br /&gt;
install with other users (and uninstalling will lose the config, which&lt;br /&gt;
maybe is not desired).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Versioning of Config==&lt;br /&gt;
&lt;br /&gt;
Hanging from the base path, we find (three digit) subdirectories to&lt;br /&gt;
allow parallel installation of different Blender versions. The value&lt;br /&gt;
is also stored in ''BLENDER_VERSION'' env var (set by program, not overrideable).&lt;br /&gt;
Examples ''255/'' or ''260/'', so a complete path would be&lt;br /&gt;
''/home/USERNAME/.blender/255/''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Common Config Paths==&lt;br /&gt;
&lt;br /&gt;
Config files are grouped into 4 classes, ''BASE'', ''DATAFILES'',&lt;br /&gt;
''PYTHON'' and ''PLUGINS''. This four classes are controlled by&lt;br /&gt;
enviroment variables ''BLENDER_USER_*'' and ''BLENDER_SYSTEM_*''&lt;br /&gt;
(''BLENDER_USER_BASE'' etc). The ''USER'' is a single path, and the&lt;br /&gt;
''SYSTEM'' is a list of paths where the system will look, in order, if&lt;br /&gt;
there is no user version. Any reference to a plugin will only need to&lt;br /&gt;
mention the relative path to the family it belongs too, and the system&lt;br /&gt;
will take care of locating the right file.&lt;br /&gt;
&lt;br /&gt;
The default values are loaded from ''environment'' file. This file is a special ''BASE'' file as it is needed to be loaded&lt;br /&gt;
before all the variables are set, so we have to make the location of&lt;br /&gt;
this file partially hardcoded, only affected by prelaunch enviroment&lt;br /&gt;
variables. Example of defaults in Unix (except ''SYSTEM_PLUGINS'' that includes a local&lt;br /&gt;
change to demostrate multiple paths):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 # This is a comment line and the next are valid Unix paths.&lt;br /&gt;
 # Notice the last envvar has two paths, separated by :&lt;br /&gt;
 #  and using a non Blender envvar&lt;br /&gt;
 BLENDER_USER_BASE=${HOME}/.blender/${BLENDER_VERSION}&lt;br /&gt;
 BLENDER_SYSTEM_BASE=${BLENDER_SHARE}/${BLENDER_VERSION}&lt;br /&gt;
 BLENDER_USER_DATAFILES=${HOME}/.blender/${BLENDER_VERSION}/datafiles&lt;br /&gt;
 BLENDER_SYSTEM_DATAFILES=${BLENDER_SHARE}/${BLENDER_VERSION}/datafiles&lt;br /&gt;
 BLENDER_USER_PY=${HOME}/.blender/${BLENDER_VERSION}/py&lt;br /&gt;
 BLENDER_SYSTEM_PY=${BLENDER_SHARE}/${BLENDER_VERSION}/py&lt;br /&gt;
 BLENDER_USER_PLUGINS=${HOME}/.blender/${BLENDER_VERSION}/plugins&lt;br /&gt;
 BLENDER_SYSTEM_PLUGINS=${BLENDER_SHARE}/${BLENDER_VERSION}/plugins:${MOVIE_PROJECT}/plugins&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So continuing with the example, if trying to load a sequencer effect&lt;br /&gt;
in Unix named ''stripes.so'', the file to ask for is a ''PLUGINS''&lt;br /&gt;
type with path ''sequencer/stripes.so''. Let's assume&lt;br /&gt;
''MOVIE_PROJECT'' has value ''/mnt/movie/'' and Blender 2.55 with full&lt;br /&gt;
install (thus ''SHARE'' as ''/usr/share/blender'') would had loaded&lt;br /&gt;
''~/.blender/250/environment'' at start up and then will try the&lt;br /&gt;
following files in order, as instructed per it:&lt;br /&gt;
''~/.blender/250/plugins/sequencer/stripes.so'',&lt;br /&gt;
''/usr/share/blender/255/plugins/sequencer/stripes.so'' and lastly&lt;br /&gt;
''/mnt/movie/plugins/sequencer/stripes.so''.&lt;br /&gt;
&lt;br /&gt;
''PY'' and ''PLUGINS'' are self descriptive, ''DATAFILES'' covers&lt;br /&gt;
things like ''startup.blend'', etc and ''BASE'' more general ones&lt;br /&gt;
like ''enviroment'' or ''file-history'' files.&lt;br /&gt;
&lt;br /&gt;
=Points of View=&lt;br /&gt;
==Developers' PoV==&lt;br /&gt;
&lt;br /&gt;
The API matches typical C calls, just like Blender uses own memory&lt;br /&gt;
allocation wrappers, we move to use file operation wrappers. They add&lt;br /&gt;
some extra parameters to specify details, and otherwise just change&lt;br /&gt;
slightly like making ''FILE*'' become ''BFILE*''. In case of need,&lt;br /&gt;
there are calls to fall back to plain C style (extract ''fd'' or&lt;br /&gt;
''FILE*'' from a ''BFILE*'', eg). The two principal parameters to look&lt;br /&gt;
for are ''int bflags'' and ''BEnvVarFam envvars'', see ''BLI_bfile.h''&lt;br /&gt;
for the current implementation.&lt;br /&gt;
&lt;br /&gt;
''bflags'' is the basic param, a bitfield that decides what special&lt;br /&gt;
handling to perform, like look up temporary file if called with&lt;br /&gt;
''BFILE_TEMP'' or compress with ''BFILE_GZIP'', or give only the&lt;br /&gt;
shared version of a config file with&lt;br /&gt;
''BFILE_CONFIG|BFILE_SYSONLY''. This determines not only what special&lt;br /&gt;
operations to perform in the data (like compression) but if any&lt;br /&gt;
operation is needed for the provided path (like look up in user config&lt;br /&gt;
then shared config).&lt;br /&gt;
&lt;br /&gt;
In the case of config files, then ''envvars'' param should specify which&lt;br /&gt;
config subtype. Otherwise just set to none.&lt;br /&gt;
&lt;br /&gt;
Example, assume we are working with ''/somewhere/foo.blend'' and we want&lt;br /&gt;
to write 2 bytes to ''//bar'' file, before it would be something like (more or less copied from real code, comments added about what&lt;br /&gt;
happens and could be improved):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 strcpy(path, &amp;quot;//bar&amp;quot;);&lt;br /&gt;
 BLI_path_abs(path, G.sce);&lt;br /&gt;
 FILE* file = fopen(path, &amp;quot;wb&amp;quot;); /* File data is already removed, no way back */&lt;br /&gt;
 /* Crash here means no new or old data avaliable */&lt;br /&gt;
 if (file)&lt;br /&gt;
   fwrite(&amp;amp;buf, 1, 2, file); /* Maybe write failed, but ignored */&lt;br /&gt;
 /* Crash here could mean loss, data not fsynced */&lt;br /&gt;
 fclose(file);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it becomes (comments explain what the lib gives us&lt;br /&gt;
automatically):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 BFILE* file = BLI_bfile_fopen(&amp;quot;//bar&amp;quot;, &amp;quot;wb&amp;quot;, BFILE_NORMAL, BENV_NONE);&lt;br /&gt;
 /* Next operations are performed over safe path, old data still avaliable */&lt;br /&gt;
 if (file)&lt;br /&gt;
   BLI_bfile_fwrite(&amp;amp;buf, 1, 2, file); /* Error ignored, but not as catastrophic as before */&lt;br /&gt;
 BLI_bfile_close(file); /* If there were errors, the data is not commited, old is kept. And it is really synced to disk to be sure. */&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basically, the new API can handle Blender paths like ''//'' or&lt;br /&gt;
&amp;quot;whereever the user config files for script are&amp;quot;, but also provides&lt;br /&gt;
extra services like backup before overwriting current data.&lt;br /&gt;
&lt;br /&gt;
It can allow standarizing in ''/'' as directory separator and then make&lt;br /&gt;
the API handle the OS details in one single location.&lt;br /&gt;
&lt;br /&gt;
==Users' PoV==&lt;br /&gt;
&lt;br /&gt;
New users should not need to touch anything, but enjoy proper&lt;br /&gt;
separation of own vs shared files, and above all, enjoy that the file&lt;br /&gt;
paths follow the expected style in the machine they are using.&lt;br /&gt;
&lt;br /&gt;
Advanced users will be able to adjust paths via&lt;br /&gt;
[[Dev:2.5/Source/Architecture/EnvironmentVariables |&lt;br /&gt;
EnvironmentVariables]], via the configuration file in their own config&lt;br /&gt;
files location. They will also be able to run external process that&lt;br /&gt;
know which Blender launched them and where to look up for things, or&lt;br /&gt;
even adjust Blender configuration via variables. In conclusion,&lt;br /&gt;
integrate better with automated systems like renderfarms or allows&lt;br /&gt;
quick configuration like testings a new set of scripts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Administrators' PoV==&lt;br /&gt;
&lt;br /&gt;
Each user has own data, central location for shared data, no writing&lt;br /&gt;
to user config until needed... all should be covered. I can think one&lt;br /&gt;
case in which Unix ones will have a small issue, plugins inside&lt;br /&gt;
''/usr/share/blender'' is not a good thing (different processor&lt;br /&gt;
types), but as the only single item that is forced is the existance of&lt;br /&gt;
''environment'' text file, they can put something like&lt;br /&gt;
''BLENDER_SYSTEM_PLUGINS=/usr/lib/blender/'' there and solve the&lt;br /&gt;
problem.&lt;/div&gt;</summary>
		<author><name>wiki&gt;Gsrb3d</name></author>
		
	</entry>
</feed>