|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Version1Update.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
|
|
3 |
VRMoo Server - Virtual Reality Object Oriented MUD Server
|
|
4 |
Copyright (C) 2001 - 2003 VRMoo Development Team
|
|
5 |
|
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify
|
|
8 |
it under the terms of the GNU General Public License as published by
|
|
9 |
the Free Software Foundation; either version 2 of the License, or
|
|
10 |
(at your option) any later version.
|
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful,
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
GNU General Public License for more details.
|
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License
|
|
18 |
along with this program; if not, write to the Free Software
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
|
|
21 |
|
|
22 |
For information about VRMoo and its authors, please visit the website:
|
|
23 |
http://www.vrmoo.org/
|
|
24 |
|
|
25 |
*/
|
|
26 |
|
|
27 |
package org.vrmoo.server.data.update;
|
|
28 |
|
|
29 |
import java.io.BufferedReader;
|
|
30 |
import java.io.File;
|
|
31 |
import java.io.IOException;
|
|
32 |
import java.io.PrintWriter;
|
|
33 |
import java.util.ArrayList;
|
|
34 |
import java.util.List;
|
|
35 |
|
|
36 |
import org.vrmoo.common.util.FileUtility;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Update the VRMoo Server data directory from version 1 to version 2.
|
|
40 |
*
|
|
41 |
* @author Jeff Weston
|
|
42 |
*/
|
|
43 |
public class Version1Update extends Update |
|
44 |
{ |
|
45 |
/**
|
|
46 |
* Update the VRMoo Server data directory from version 1 to version 2.
|
|
47 |
*
|
|
48 |
* @throws IOException for any IO errors that occur
|
|
49 |
*/
|
|
50 | 0 |
public void update( ) throws IOException |
51 |
{ |
|
52 | 0 |
System.out.println( |
53 |
"Updating data directory from version 1 to version 2." );
|
|
54 |
|
|
55 | 0 |
File worldsDir = new File( "data/worlds" ); |
56 | 0 |
FileUtility.ensureDirectoryExists( worldsDir ); |
57 |
|
|
58 | 0 |
File[ ] files = worldsDir.listFiles( ); |
59 | 0 |
for ( int i = 0; i < files.length; i++ ) |
60 |
{ |
|
61 | 0 |
if ( files[ i ].isDirectory( ) )
|
62 |
{ |
|
63 | 0 |
handleVisibleObjects( files[ i ].getName( ) ); |
64 | 0 |
handleAppearances( files[ i ].getName( ) ); |
65 |
} |
|
66 |
} |
|
67 |
|
|
68 | 0 |
PrintWriter printWriter = FileUtility.getPrintWriter( |
69 |
"data/version.dat" );
|
|
70 | 0 |
printWriter.println( 2 ); |
71 | 0 |
printWriter.close( ); |
72 |
} |
|
73 |
|
|
74 |
/**
|
|
75 |
* Update the visible objects for the specified world.
|
|
76 |
*
|
|
77 |
* @param worldName the world to update
|
|
78 |
*
|
|
79 |
* @throws IOException for any IO errors that occur
|
|
80 |
*/
|
|
81 | 0 |
private void handleVisibleObjects( String worldName ) throws IOException |
82 |
{ |
|
83 | 0 |
List lines = new ArrayList( );
|
84 | 0 |
BufferedReader reader = FileUtility.getBufferedReader( |
85 |
"data/worlds/" + worldName + "/visibleObjects.dat" ); |
|
86 |
|
|
87 | 0 |
String line = reader.readLine( ); |
88 |
|
|
89 | 0 |
while ( line != null ) |
90 |
{ |
|
91 | 0 |
int index1 = line.indexOf( "," ); |
92 | 0 |
int index2 = line.indexOf( ",", index1 + 1 ); |
93 | 0 |
String part1 = line.substring( 0, index2 ); |
94 | 0 |
String part2 = line.substring( index2 ); |
95 | 0 |
lines.add( part1 + ", NULL" + part2 );
|
96 | 0 |
line = reader.readLine( ); |
97 |
} |
|
98 | 0 |
reader.close( ); |
99 |
|
|
100 | 0 |
PrintWriter writer = FileUtility.getPrintWriter( |
101 |
"data/worlds/" + worldName + "/visibleObjects.dat" ); |
|
102 |
|
|
103 | 0 |
for ( int i = 0; i < lines.size( ); i++ ) |
104 |
{ |
|
105 | 0 |
writer.println( lines.get( i ) ); |
106 |
} |
|
107 | 0 |
writer.close( ); |
108 |
} |
|
109 |
|
|
110 |
/**
|
|
111 |
* Update the appearances for the specified world.
|
|
112 |
*
|
|
113 |
* @param worldName the world to update
|
|
114 |
*
|
|
115 |
* @throws IOException for any IO errors that occur
|
|
116 |
*/
|
|
117 | 0 |
private void handleAppearances( String worldName ) throws IOException |
118 |
{ |
|
119 | 0 |
List lines = new ArrayList( );
|
120 | 0 |
BufferedReader reader = FileUtility.getBufferedReader( |
121 |
"data/worlds/" + worldName + "/appearances.dat" ); |
|
122 |
|
|
123 | 0 |
String line = reader.readLine( ); |
124 |
|
|
125 | 0 |
while ( line != null ) |
126 |
{ |
|
127 | 0 |
int index = line.indexOf( ")" ); |
128 | 0 |
String part1 = line.substring( 0, index ).trim( ); |
129 | 0 |
lines.add( part1 + ", 1.0 )" );
|
130 | 0 |
line = reader.readLine( ); |
131 |
} |
|
132 | 0 |
reader.close( ); |
133 |
|
|
134 | 0 |
PrintWriter writer = FileUtility.getPrintWriter( |
135 |
"data/worlds/" + worldName + "/appearances.dat" ); |
|
136 |
|
|
137 | 0 |
for ( int i = 0; i < lines.size( ); i++ ) |
138 |
{ |
|
139 | 0 |
writer.println( lines.get( i ) ); |
140 |
} |
|
141 | 0 |
writer.close( ); |
142 |
} |
|
143 |
} |
|
144 |
|
|