-
Notifications
You must be signed in to change notification settings - Fork 0
/
Advanced_ChangeSaveLocation.js
139 lines (134 loc) · 4.19 KB
/
Advanced_ChangeSaveLocation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*:
* @plugindesc Advanced - Change Save Location (MV and MZ)
* Version 0.5 Beta (Works only on Windows with NW.js)
* Last update: 28/08/2023
* @author DevWithCoffee (Aka Dev_With_Coffee)
*
* @param location
* @desc If you try to enter manually it will be set to Default automatically
* @type select
* @default {Game}\save\
* @option {Game}\save\
* @value Default
* @option {Game}\
* @value Current Folder
* @option {SO}:\ProgramData\
* @value ProgramData
* @option {SO}:\Users\{User}\Appdata\Local\
* @value Appdata-Local
* @option {SO}:\Users\{User}\Appdata\Roaming\
* @value Appdata-Roaming
* @option {SO}:\Users\Public\Documents\
* @value Public Documents
* @option {SO}:\Users\{User}\
* @value Current User
* @option {SO}:\Users\{User}\Documents\
* @value Documents of Current User
*
* @param dir_save_name
* @desc To set a different name change to "Text" and enter manually
* @type select
* @default GameTitle
* @option GameTitle
* @value GameTitle
* @option GameTitle (without space)
* @value TitleNoSpace
* @option GameTitle (underline replaces spaces)
* @value TitleWithUnderline
*
* @help Advanced_ChangeSaveLocation.js
* location: Here you define the path to the savefiles
* {Game} is where files are located, like Game.exe
* {SO} is the drive where the operating system is installed, like C
* {User} is the connected user's folder
*
* dir_save_name: Here you define whether you want savefiles to be
* created in a new folder.
* This option does not work with "{Game}\save\" or "{Game}\".
*
* GameTitle: The folder will be named the same as the title in the game bar
* GameTitle (without space): An extra option
* GameTitle (underline replaces spaces): Another extra option
* Developer defined: To set a different name change to "Text"
*
* Warning: Symbols, accented letters and non-English characters
* will be removed automatically, except "+", "-" and "_"
*/
(function() {
if (process.env.OS == "Windows_NT" && Utils.isNwjs()) {
var path = require('path');
var base = path.dirname(process.mainModule.filename);
var new_path = "";
var parameters = PluginManager.parameters('Advanced_ChangeSaveLocation');
switch (parameters['location']) {
case "Default":
new_path = path.join(base, 'save/');
break;
case "Current Folder":
new_path = path.join(base, '/');
break;
case "ProgramData":
new_path = process.env.ProgramData || process.env.ALLUSERSPROFILE;
break;
case "Appdata-Local":
new_path = process.env.LOCALAPPDATA || process.env.LOCAL_APPDATA;
break;
case "Appdata-Roaming":
new_path = process.env.APPDATA;
break;
case "Public Documents":
new_path = process.env.PUBLIC+"/Documents";
break;
case "Current User":
new_path = process.env.USERPROFILE;
break;
case "Documents of Current User":
new_path = process.env.USERPROFILE+"/Documents";
break;
default:
parameters['location'] = "Default";
new_path = path.join(base, 'save/');
}
if (parameters['location'] != "Default" && parameters['location'] != "Current Folder"){
var mkdirsaves = true;
var convtitle = document.title;
convtitle = convtitle.replace(/[^a-zA-Z0-9\_\-\+\s]/g,"");
switch (parameters['dir_save_name']) {
case "GameTitle":
new_path = new_path+"/"+convtitle+"/";
break;
case "TitleNoSpace":
convtitle = convtitle.replace(/\s/g,"");
new_path = new_path+"/"+convtitle+"/";
break;
case "TitleWithUnderline":
convtitle = convtitle.replace(/\s/g,"_");
new_path = new_path+"/"+convtitle+"/";
break;
default:
var dev_defined = parameters['dir_save_name'];
dev_defined = dev_defined.replace(/[^a-zA-Z0-9\s\_\-]/g,"");
new_path = new_path+"/"+dev_defined+"/";
}
if(new_path.slice(-2) == "//"){
new_path = path.join(base, 'save/');
}
var fs = require('fs');
if(!fs.existsSync(new_path)){
fs.mkdirSync(new_path);
}
}
/* RMMV */
if(StorageManager.localFileDirectoryPath){
StorageManager.localFileDirectoryPath = function() {
return new_path;
};
}
/* RMMZ */
if(StorageManager.fileDirectoryPath){
StorageManager.fileDirectoryPath = function() {
return new_path;
}
}
}
})();