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

Collapse All | Expand All

(-)a/renpy.py (-128 / +4 lines)
Lines 28-148 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
51
    # Makes sure the permissions are right on the save directory.
52
    def test_writable(d):
53
        try:
54
            fn = os.path.join(d, "test.txt")
55
            open(fn, "w").close()
56
            open(fn, "r").close()
57
            os.unlink(fn)
58
            return True
59
        except:
60
            return False
61
62
    # Android.
63
    if renpy.android:
64
        paths = [
65
            os.path.join(os.environ["ANDROID_OLD_PUBLIC"], "game/saves"),
66
            os.path.join(os.environ["ANDROID_PRIVATE"], "saves"),
67
            os.path.join(os.environ["ANDROID_PUBLIC"], "saves"),
68
            ]
69
70
        for rv in paths:
71
            if os.path.isdir(rv) and test_writable(rv):
72
                break
73
74
        print("Saving to", rv)
75
76
        # We return the last path as the default.
77
78
        return rv
79
80
    if renpy.ios:
81
        from pyobjus import autoclass
82
        from pyobjus.objc_py_types import enum
83
84
        NSSearchPathDirectory = enum("NSSearchPathDirectory", NSDocumentDirectory=9)
85
        NSSearchPathDomainMask = enum("NSSearchPathDomainMask", NSUserDomainMask=1)
86
87
        NSFileManager = autoclass('NSFileManager')
88
        manager = NSFileManager.defaultManager()
89
        url = manager.URLsForDirectory_inDomains_(
90
            NSSearchPathDirectory.NSDocumentDirectory,
91
            NSSearchPathDomainMask.NSUserDomainMask,
92
            ).lastObject()
93
94
        # url.path seems to change type based on iOS version, for some reason.
95
        try:
96
            rv = url.path().UTF8String().decode("utf-8")
97
        except:
98
            rv = url.path.UTF8String().decode("utf-8")
99
100
        print("Saving to", rv)
101
        return rv
102
103
    # No save directory given.
104
    if not save_directory:
105
        return gamedir + "/saves"
106
107
    # Search the path above Ren'Py for a directory named "Ren'Py Data".
108
    # If it exists, then use that for our save directory.
109
    path = renpy.config.renpy_base
110
111
    while True:
112
        if os.path.isdir(path + "/Ren'Py Data"):
113
            return path + "/Ren'Py Data/" + save_directory
114
115
        newpath = os.path.dirname(path)
116
        if path == newpath:
117
            break
118
        path = newpath
119
120
    # Otherwise, put the saves in a platform-specific location.
121
    if renpy.macintosh:
122
        rv = "~/Library/RenPy/" + save_directory
123
        return os.path.expanduser(rv)
124
125
    elif renpy.windows:
126
        if 'APPDATA' in os.environ:
127
            return os.environ['APPDATA'] + "/RenPy/" + save_directory
128
        else:
129
            rv = "~/RenPy/" + renpy.config.save_directory
130
            return os.path.expanduser(rv)
131
132
    else:
133
        rv = "~/.renpy/" + save_directory
134
        return os.path.expanduser(rv)
135
136
137
# Returns the path to the Ren'Py base directory (containing common and
138
# the launcher, usually.)
139
def path_to_renpy_base():
140
    renpy_base = os.path.dirname(os.path.realpath(sys.argv[0]))
141
    renpy_base = os.path.abspath(renpy_base)
142
143
    return renpy_base
144
145
##############################################################################
146
34
147
# The version of the Mac Launcher and py4renpy that we require.
35
# The version of the Mac Launcher and py4renpy that we require.
148
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 (-4 / +3 lines)
Lines 27-33 import os Link Here
27
import sys
27
import sys
28
import time
28
import time
29
import zipfile
29
import zipfile
30
import __main__
30
import renpy.common as common
31
31
32
32
33
last_clock = time.time()
33
last_clock = time.time()
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
378
- 

Return to bug 587872