1 |
fcf7320f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2022 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.network;
|
21 |
|
|
|
22 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23 |
|
|
|
24 |
|
|
import org.distorted.objects.RubikObjectList;
|
25 |
|
|
|
26 |
|
|
import java.util.ArrayList;
|
27 |
|
|
|
28 |
|
|
public class RubikUpdates
|
29 |
|
|
{
|
30 |
|
|
public static class UpdateInfo
|
31 |
|
|
{
|
32 |
|
|
public final String mObjectName;
|
33 |
|
|
public final int mMinorVersion;
|
34 |
|
|
|
35 |
|
|
public UpdateInfo(String name,int version)
|
36 |
|
|
{
|
37 |
|
|
mObjectName = name;
|
38 |
|
|
mMinorVersion= version;
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
private String mUrl;
|
43 |
|
|
private final ArrayList<UpdateInfo> mNewObjects;
|
44 |
|
|
private final ArrayList<UpdateInfo> mNewExtras;
|
45 |
|
|
private final ArrayList<UpdateInfo> mUpdObjects;
|
46 |
|
|
private final ArrayList<UpdateInfo> mUpdExtras;
|
47 |
|
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
|
50 |
|
|
public RubikUpdates()
|
51 |
|
|
{
|
52 |
|
|
mNewObjects = new ArrayList<>();
|
53 |
|
|
mNewExtras = new ArrayList<>();
|
54 |
|
|
mUpdObjects = new ArrayList<>();
|
55 |
|
|
mUpdExtras = new ArrayList<>();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
|
|
private String debug(ArrayList<UpdateInfo> list)
|
61 |
|
|
{
|
62 |
|
|
String ret = "";
|
63 |
|
|
for( UpdateInfo info : list) ret += (" "+info.mObjectName+" "+info.mMinorVersion);
|
64 |
|
|
return ret;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
|
|
private void parseLine(String[] elements)
|
70 |
|
|
{
|
71 |
|
|
String objName = elements[0];
|
72 |
|
|
String objMinor = elements[1];
|
73 |
|
|
String extMinor = elements[2];
|
74 |
|
|
int oMinor, eMinor;
|
75 |
|
|
|
76 |
|
|
try { oMinor = Integer.parseInt(objMinor); }
|
77 |
|
|
catch (NumberFormatException ex) { oMinor = -1; }
|
78 |
|
|
try { eMinor = Integer.parseInt(extMinor); }
|
79 |
|
|
catch (NumberFormatException ex) { eMinor = -1; }
|
80 |
|
|
|
81 |
|
|
int objOrdinal = RubikObjectList.getOrdinal(objName.toUpperCase());
|
82 |
|
|
|
83 |
|
|
if( oMinor>=0 )
|
84 |
|
|
{
|
85 |
|
|
if( objOrdinal>=0 )
|
86 |
|
|
{
|
87 |
|
|
int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal);
|
88 |
|
|
if( localObjectMinor>=0 && localObjectMinor<oMinor )
|
89 |
|
|
{
|
90 |
|
|
UpdateInfo info = new UpdateInfo(objName,oMinor);
|
91 |
|
|
mUpdObjects.add(info);
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
else
|
95 |
|
|
{
|
96 |
|
|
UpdateInfo info = new UpdateInfo(objName,oMinor);
|
97 |
|
|
mNewObjects.add(info);
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
if( eMinor>=0 )
|
102 |
|
|
{
|
103 |
|
|
if( objOrdinal>=0 )
|
104 |
|
|
{
|
105 |
|
|
int localExtrasMinor = RubikObjectList.getLocalExtrasMinor(objOrdinal);
|
106 |
|
|
if( localExtrasMinor>=0 && localExtrasMinor<eMinor )
|
107 |
|
|
{
|
108 |
|
|
UpdateInfo info = new UpdateInfo(objName,eMinor);
|
109 |
|
|
mUpdExtras.add(info);
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
else
|
113 |
|
|
{
|
114 |
|
|
UpdateInfo info = new UpdateInfo(objName,eMinor);
|
115 |
|
|
mNewExtras.add(info);
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121 |
|
|
|
122 |
|
|
void parse(String updates)
|
123 |
|
|
{
|
124 |
|
|
android.util.Log.e("D", updates);
|
125 |
|
|
|
126 |
|
|
mNewObjects.clear();
|
127 |
|
|
mNewExtras.clear();
|
128 |
|
|
mUpdObjects.clear();
|
129 |
|
|
mUpdExtras.clear();
|
130 |
|
|
|
131 |
|
|
String[] lines = updates.split("\n");
|
132 |
|
|
int numLines = lines.length;
|
133 |
|
|
|
134 |
|
|
if( numLines>=1 )
|
135 |
|
|
{
|
136 |
|
|
mUrl = lines[0];
|
137 |
|
|
for(int line=1; line<numLines; line++)
|
138 |
|
|
{
|
139 |
|
|
String[] elements = lines[line].split(" ");
|
140 |
|
|
if( elements.length>=3 ) parseLine(elements);
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
63dd19c4
|
Leszek Koltunski
|
}
|
144 |
|
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
fcf7320f
|
Leszek Koltunski
|
|
147 |
63dd19c4
|
Leszek Koltunski
|
public void showDebug()
|
148 |
|
|
{
|
149 |
fcf7320f
|
Leszek Koltunski
|
android.util.Log.e("D", "url: "+mUrl);
|
150 |
|
|
android.util.Log.e("D", "new objects: "+debug(mNewObjects));
|
151 |
|
|
android.util.Log.e("D", "new extras : "+debug(mNewExtras ));
|
152 |
|
|
android.util.Log.e("D", "upd objects: "+debug(mUpdObjects));
|
153 |
|
|
android.util.Log.e("D", "upd extras : "+debug(mUpdExtras ));
|
154 |
|
|
}
|
155 |
|
|
}
|