1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 mObjectShortName;
|
33
|
public final String mObjectLongName;
|
34
|
public final String mDescription;
|
35
|
public final int mObjectMinorVersion;
|
36
|
public final int mExtrasMinorVersion;
|
37
|
public final boolean mUpdateObject;
|
38
|
public final boolean mUpdateExtras;
|
39
|
|
40
|
public UpdateInfo(String shortName, String longName, String description, int objectMinor, int extrasMinor, boolean updateO, boolean updateE)
|
41
|
{
|
42
|
mObjectShortName = shortName;
|
43
|
mObjectLongName = longName;
|
44
|
mDescription = description;
|
45
|
mObjectMinorVersion = objectMinor;
|
46
|
mExtrasMinorVersion = extrasMinor;
|
47
|
mUpdateObject = updateO;
|
48
|
mUpdateExtras = updateE;
|
49
|
}
|
50
|
}
|
51
|
|
52
|
private int mNumberOfUpdates;
|
53
|
private String mUrl;
|
54
|
private final ArrayList<UpdateInfo> mNew, mUpd;
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
public RubikUpdates()
|
59
|
{
|
60
|
mNew = new ArrayList<>();
|
61
|
mUpd = new ArrayList<>();
|
62
|
}
|
63
|
|
64
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65
|
|
66
|
private String debug(ArrayList<UpdateInfo> list)
|
67
|
{
|
68
|
String ret = "";
|
69
|
|
70
|
for( UpdateInfo info : list)
|
71
|
{
|
72
|
ret += (info.mObjectShortName+" "+info.mObjectLongName+" "+info.mDescription+" ");
|
73
|
ret += (info.mObjectMinorVersion+" "+info.mExtrasMinorVersion+" "+info.mUpdateObject+" "+info.mUpdateExtras+" , ");
|
74
|
}
|
75
|
|
76
|
return ret;
|
77
|
}
|
78
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
private void parseLine(String[] elements)
|
82
|
{
|
83
|
boolean added = false;
|
84
|
String shortName = elements[0];
|
85
|
String objMinor = elements[1];
|
86
|
String extMinor = elements[2];
|
87
|
String longName = elements[3];
|
88
|
String description = elements[4];
|
89
|
int oMinor, eMinor;
|
90
|
|
91
|
try { oMinor = Integer.parseInt(objMinor); }
|
92
|
catch (NumberFormatException ex) { oMinor = -1; }
|
93
|
try { eMinor = Integer.parseInt(extMinor); }
|
94
|
catch (NumberFormatException ex) { eMinor = -1; }
|
95
|
|
96
|
if( oMinor>=0 && eMinor>=0 )
|
97
|
{
|
98
|
int objOrdinal = RubikObjectList.getOrdinal(shortName.toUpperCase());
|
99
|
|
100
|
if( objOrdinal>=0 )
|
101
|
{
|
102
|
int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal);
|
103
|
int localExtrasMinor = RubikObjectList.getLocalExtrasMinor(objOrdinal);
|
104
|
boolean updateO = localObjectMinor<oMinor;
|
105
|
boolean updateE = localExtrasMinor<eMinor;
|
106
|
|
107
|
if( updateO || updateE )
|
108
|
{
|
109
|
UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,updateO,updateE);
|
110
|
mUpd.add(info);
|
111
|
added = true;
|
112
|
}
|
113
|
}
|
114
|
else
|
115
|
{
|
116
|
UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,true,true);
|
117
|
mNew.add(info);
|
118
|
added = true;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
if( added ) mNumberOfUpdates++;
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
void parse(String updates)
|
128
|
{
|
129
|
android.util.Log.e("D", updates);
|
130
|
|
131
|
mNumberOfUpdates = 0;
|
132
|
|
133
|
mNew.clear();
|
134
|
mUpd.clear();
|
135
|
|
136
|
String[] lines = updates.split("\n");
|
137
|
int numLines = lines.length;
|
138
|
|
139
|
if( numLines>=1 )
|
140
|
{
|
141
|
mUrl = lines[0];
|
142
|
for(int line=1; line<numLines; line++)
|
143
|
{
|
144
|
String[] elements = lines[line].split(",");
|
145
|
if( elements.length>=3 ) parseLine(elements);
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
|
150
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151
|
|
152
|
public int getNumberOfUpdates()
|
153
|
{
|
154
|
return mNumberOfUpdates;
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public void showDebug()
|
160
|
{
|
161
|
android.util.Log.e("D", "url: "+mUrl);
|
162
|
android.util.Log.e("D", "new objects: "+debug(mNew));
|
163
|
android.util.Log.e("D", "upd objects: "+debug(mUpd));
|
164
|
}
|
165
|
}
|