Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 671008 | Differences between
and this patch

Collapse All | Expand All

(-)a/renpy.py (-129 / +4 lines)
Lines 28-149 Link Here
28
import os
28
import os
29
import sys
29
import sys
30
import warnings
30
import warnings
31
31
from distutils.sysconfig import get_python_lib
32
# Functions to be customized by distributors. ################################
32
sys.path.append(get_python_lib() + "/renpy@SLOT@")
33
33
import renpy.common as common
34
# Given the Ren'Py base directory (usually the directory containing
35
# this file), this is expected to return the path to the common directory.
36
37
38
def path_to_common(renpy_base):
39
    return renpy_base + "/renpy/common"
40
41
# Given a directory holding a Ren'Py game, this is expected to return
42
# the path to a directory that will hold save files.
43
44
45
def path_to_saves(gamedir, save_directory=None):
46
    import renpy  # @UnresolvedImport
47
48
    if save_directory is None:
49
        save_directory = renpy.config.save_directory
50
        save_directory = renpy.exports.fsencode(save_directory)
51
52
    # Makes sure the permissions are right on the save directory.
53
    def test_writable(d):
54
        try:
55
            fn = os.path.join(d, "test.txt")
56
            open(fn, "w").close()
57
            open(fn, "r").close()
58
            os.unlink(fn)
59
            return True
60
        except:
61
            return False
62
63
    # Android.
64
    if renpy.android:
65
        paths = [
66
            os.path.join(os.environ["ANDROID_OLD_PUBLIC"], "game/saves"),
67
            os.path.join(os.environ["ANDROID_PRIVATE"], "saves"),
68
            os.path.join(os.environ["ANDROID_PUBLIC"], "saves"),
69
            ]
70
71
        for rv in paths:
72
            if os.path.isdir(rv) and test_writable(rv):
73
                break
74
75
        print("Saving to", rv)
76
77
        # We return the last path as the default.
78
79
        return rv
80
81
    if renpy.ios:
82
        from pyobjus import autoclass
83
        from pyobjus.objc_py_types import enum
84
85
        NSSearchPathDirectory = enum("NSSearchPathDirectory", NSDocumentDirectory=9)
86
        NSSearchPathDomainMask = enum("NSSearchPathDomainMask", NSUserDomainMask=1)
87
88
        NSFileManager = autoclass('NSFileManager')
89
        manager = NSFileManager.defaultManager()
90
        url = manager.URLsForDirectory_inDomains_(
91
            NSSearchPathDirectory.NSDocumentDirectory,
92
            NSSearchPathDomainMask.NSUserDomainMask,
93
            ).lastObject()
94
95
        # url.path seems to change type based on iOS version, for some reason.
96
        try:
97
            rv = url.path().UTF8String().decode("utf-8")
98
        except:
99
            rv = url.path.UTF8String().decode("utf-8")
100
101
        print("Saving to", rv)
102
        return rv
103
104
    # No save directory given.
105
    if not save_directory:
106
        return gamedir + "/saves"
107
108
    # Search the path above Ren'Py for a directory named "Ren'Py Data".
109
    # If it exists, then use that for our save directory.
110
    path = renpy.config.renpy_base
111
112
    while True:
113
        if os.path.isdir(path + "/Ren'Py Data"):
114
            return path + "/Ren'Py Data/" + save_directory
115
116
        newpath = os.path.dirname(path)
117
        if path == newpath:
118
            break
119
        path = newpath
120
121
    # Otherwise, put the saves in a platform-specific location.
122
    if renpy.macintosh:
123
        rv = "~/Library/RenPy/" + save_directory
124
        return os.path.expanduser(rv)
125
126
    elif renpy.windows:
127
        if 'APPDATA' in os.environ:
128
            return os.environ['APPDATA'] + "/RenPy/" + save_directory
129
        else:
130
            rv = "~/RenPy/" + renpy.config.save_directory
131
            return os.path.expanduser(rv)
132
133
    else:
134
        rv = "~/.renpy/" + save_directory
135
        return os.path.expanduser(rv)
136
137
138
# Returns the path to the Ren'Py base directory (containing common and
139
# the launcher, usually.)
140
def path_to_renpy_base():
141
    renpy_base = os.path.dirname(os.path.realpath(sys.argv[0]))
142
    renpy_base = os.path.abspath(renpy_base)
143
144
    return renpy_base
145
146
##############################################################################
147
34
148
# The version of the Mac Launcher and py4renpy that we require.
35
# The version of the Mac Launcher and py4renpy that we require.
149
macos_version = (6, 14, 0)
36
macos_version = (6, 14, 0)
Lines 154-174 except: Link Here
154
    print("Ren'Py requires at least python 2.6.")
45
    print("Ren'Py requires at least python 2.6.")
155
    sys.exit(0)
46
    sys.exit(0)
156
47
157
android = ("ANDROID_PRIVATE" in os.environ)
158
159
# Android requires us to add code to the main module, and to command some
160
# renderers.
161
if android:
162
    __main__ = sys.modules["__main__"]
163
    __main__.path_to_renpy_base = path_to_renpy_base
164
    __main__.path_to_common = path_to_common
165
    __main__.path_to_saves = path_to_saves
166
    os.environ["RENPY_RENDERER"] = "gl"
167
168
169
def main():
48
def main():
170
49
171
    renpy_base = path_to_renpy_base()
50
    renpy_base = common.path_to_renpy_base()
172
51
173
    # Add paths.
52
    # Add paths.
174
    if os.path.exists(renpy_base + "/module"):
53
    if os.path.exists(renpy_base + "/module"):
(-)a/renpy/common.py (+137 lines)
Line 0 Link Here
1
# This file is part of Ren'Py. The license below applies to Ren'Py only.
2
# Games and other projects that use Ren'Py may use a different license.
3
4
# Copyright 2004-2015 Tom Rothamel <pytom@bishoujo.us>
5
#
6
# Permission is hereby granted, free of charge, to any person
7
# obtaining a copy of this software and associated documentation files
8
# (the "Software"), to deal in the Software without restriction,
9
# including without limitation the rights to use, copy, modify, merge,
10
# publish, distribute, sublicense, and/or sell copies of the Software,
11
# and to permit persons to whom the Software is furnished to do so,
12
# subject to the following conditions:
13
#
14
# The above copyright notice and this permission notice shall be
15
# included in all copies or substantial portions of the Software.
16
#
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
import os
26
import sys
27
import warnings
28
from distutils.sysconfig import get_python_lib
29
30
# Given the Ren'Py base directory (usually the directory containing
31
# this file), this is expected to return the path to the common directory.
32
def path_to_common(renpy_base):
33
    return renpy_base + "/renpy/common"
34
35
# Given a directory holding a Ren'Py game, this is expected to return
36
# the path to a directory that will hold save files.
37
def path_to_saves(gamedir, save_directory=None):
38
    import renpy #@UnresolvedImport
39
40
    if save_directory is None:
41
        save_directory = renpy.config.save_directory
42
43
    # Makes sure the permissions are right on the save directory.
44
    def test_writable(d):
45
        try:
46
            fn = os.path.join(d, "test.txt")
47
            open(fn, "w").close()
48
            open(fn, "r").close()
49
            os.unlink(fn)
50
            return True
51
        except:
52
            return False
53
54
55
    # Android.
56
    if renpy.android:
57
        paths = [
58
            os.path.join(os.environ["ANDROID_OLD_PUBLIC"], "game/saves"),
59
            os.path.join(os.environ["ANDROID_PRIVATE"], "saves"),
60
            os.path.join(os.environ["ANDROID_PUBLIC"], "saves"),
61
            ]
62
63
        for rv in paths:
64
            if os.path.isdir(rv) and test_writable(rv):
65
                break
66
67
        print "Saving to", rv
68
69
        # We return the last path as the default.
70
71
        return rv
72
73
    if renpy.ios:
74
        from pyobjus import autoclass
75
        from pyobjus.objc_py_types import enum
76
77
        NSSearchPathDirectory = enum("NSSearchPathDirectory", NSDocumentDirectory=9)
78
        NSSearchPathDomainMask = enum("NSSearchPathDomainMask", NSUserDomainMask=1)
79
80
        NSFileManager = autoclass('NSFileManager')
81
        manager = NSFileManager.defaultManager()
82
        url = manager.URLsForDirectory_inDomains_(
83
            NSSearchPathDirectory.NSDocumentDirectory,
84
            NSSearchPathDomainMask.NSUserDomainMask,
85
            ).lastObject()
86
87
        # url.path seems to change type based on iOS version, for some reason.
88
        try:
89
            rv = url.path().UTF8String().decode("utf-8")
90
        except:
91
            rv = url.path.UTF8String().decode("utf-8")
92
93
        print "Saving to", rv
94
        return rv
95
96
    # No save directory given.
97
    if not save_directory:
98
        return gamedir + "/saves"
99
100
    # Search the path above Ren'Py for a directory named "Ren'Py Data".
101
    # If it exists, then use that for our save directory.
102
    path = renpy.config.renpy_base
103
104
    while True:
105
        if os.path.isdir(path + "/Ren'Py Data"):
106
            return path + "/Ren'Py Data/" + save_directory
107
108
        newpath = os.path.dirname(path)
109
        if path == newpath:
110
            break
111
        path = newpath
112
113
    # Otherwise, put the saves in a platform-specific location.
114
    if renpy.macintosh:
115
        rv = "~/Library/RenPy/" + save_directory
116
        return os.path.expanduser(rv)
117
118
    elif renpy.windows:
119
        if 'APPDATA' in os.environ:
120
            return os.environ['APPDATA'] + "/RenPy/" + save_directory
121
        else:
122
            rv = "~/RenPy/" + renpy.config.save_directory
123
            return os.path.expanduser(rv)
124
125
    else:
126
        rv = "~/.renpy/" + save_directory
127
        return os.path.expanduser(rv)
128
129
130
# Returns the path to the Ren'Py base directory (containing common and
131
# the launcher, usually.)
132
def path_to_renpy_base():
133
    renpy_base = os.path.dirname(os.path.realpath(sys.argv[0]))
134
    renpy_base = get_python_lib() + "/renpy@SLOT@"
135
    renpy_base = os.path.abspath(renpy_base)
136
137
    return renpy_base
(-)a/renpy/main.py (-3 / +3 lines)
Lines 27-33 import os Link Here
27
import zipfile
27
import zipfile
28
import gc
28
import gc
29
import __main__
29
import renpy.common as common
30
30
31
last_clock = time.time()
31
last_clock = time.time()
32
32
Lines 273-279 def main(): Link Here
273
    renpy.config.searchpath = [ renpy.config.gamedir ]
273
    renpy.config.searchpath = [ renpy.config.gamedir ]
274
274
275
    # Find the common directory.
275
    # Find the common directory.
276
    commondir = __main__.path_to_common(renpy.config.renpy_base)  # E1101 @UndefinedVariable
276
    commondir = common.path_to_common(renpy.config.renpy_base)  # E1101 @UndefinedVariable
277
277
278
    if os.path.isdir(commondir):
278
    if os.path.isdir(commondir):
279
        renpy.config.searchpath.append(commondir)
279
        renpy.config.searchpath.append(commondir)
Lines 371-377 def main(): Link Here
371
371
372
    # Find the save directory.
372
    # Find the save directory.
373
    if renpy.config.savedir is None:
373
    if renpy.config.savedir is None:
374
        renpy.config.savedir = __main__.path_to_saves(renpy.config.gamedir)  # E1101 @UndefinedVariable
374
        renpy.config.savedir = common.path_to_saves(renpy.config.gamedir)  # E1101 @UndefinedVariable
375
375
376
    if renpy.game.args.savedir:  # @UndefinedVariable
376
    if renpy.game.args.savedir:  # @UndefinedVariable
377
        renpy.config.savedir = renpy.game.args.savedir  # @UndefinedVariable
377
        renpy.config.savedir = renpy.game.args.savedir  # @UndefinedVariable
(-)a/renpy/script.py (-3 / +2 lines)
Lines 150-157 import os Link Here
150
           if renpy.loader.loadable(i):
150
           if renpy.loader.loadable(i):
151
               return None
151
               return None
152
        import __main__
152
        import renpy.common as common
153
        backups = __main__.path_to_saves(renpy.config.gamedir, "backups")  # @UndefinedVariable
153
        backups = common.path_to_saves(renpy.config.gamedir, "backups")  # @UndefinedVariable
154
       if backups is None:
154
       if backups is None:
155
           return
155
           return
156
- 

Return to bug 671008