New user fixes.
This commit is contained in:
parent
38f09021b3
commit
978b758079
@ -90,7 +90,7 @@ public class CollectionListModel<E> extends AbstractListModel<E>
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "unchecked", "SuspiciousMethodCalls" })
|
@SuppressWarnings({ "unchecked", "SuspiciousMethodCalls" })
|
||||||
public synchronized void setSelectedItem(@Nullable final Object newSelectedItem) {
|
public synchronized void setSelectedItem(@Nullable final Object newSelectedItem) {
|
||||||
if (!Objects.equals( selectedItem, newSelectedItem ) && model.contains( newSelectedItem )) {
|
if (!Objects.equals( selectedItem, newSelectedItem )) {
|
||||||
selectedItem = (E) newSelectedItem;
|
selectedItem = (E) newSelectedItem;
|
||||||
|
|
||||||
fireContentsChanged( this, -1, -1 );
|
fireContentsChanged( this, -1, -1 );
|
||||||
|
@ -431,8 +431,9 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
|
|||||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents( clipboardContents, null );
|
Toolkit.getDefaultToolkit().getSystemClipboard().setContents( clipboardContents, null );
|
||||||
|
|
||||||
Res.ui( () -> {
|
Res.ui( () -> {
|
||||||
Window window = SwingUtilities.windowForComponent( this );
|
Window window = SwingUtilities.windowForComponent( UserContentPanel.this );
|
||||||
window.dispatchEvent( new WindowEvent( window, WindowEvent.WINDOW_CLOSING ) );
|
if (window != null)
|
||||||
|
window.dispatchEvent( new WindowEvent( window, WindowEvent.WINDOW_CLOSING ) );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public abstract class MPBasicQuestion extends Changeable implements MPQuestion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
return (this == obj) || ((obj instanceof MPQuestion) && Objects.equals( getKeyword(), ((MPQuestion) obj).getKeyword() ));
|
return this == obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -204,7 +204,7 @@ public abstract class MPBasicSite<U extends MPUser<?>, Q extends MPQuestion> ext
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
return (this == obj) || ((obj instanceof MPSite) && Objects.equals( getSiteName(), ((MPSite<?>) obj).getSiteName() ));
|
return obj == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -226,7 +226,7 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
return (this == obj) || ((obj instanceof MPUser) && Objects.equals( getFullName(), ((MPUser<?>) obj).getFullName() ));
|
return this == obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,89 +104,90 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
|
|||||||
throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
|
throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
|
||||||
user.ignoreChanges();
|
user.ignoreChanges();
|
||||||
|
|
||||||
try (Reader reader = new InputStreamReader( new FileInputStream( user.getFile() ), Charsets.UTF_8 )) {
|
if (user.getFile().exists())
|
||||||
byte[] keyID = null;
|
try (Reader reader = new InputStreamReader( new FileInputStream( user.getFile() ), Charsets.UTF_8 )) {
|
||||||
String fullName = null;
|
byte[] keyID = null;
|
||||||
int mpVersion = 0, importFormat = 0, avatar = 0;
|
String fullName = null;
|
||||||
boolean clearContent = false, headerStarted = false, headerEnded = false;
|
int mpVersion = 0, importFormat = 0, avatar = 0;
|
||||||
MPResultType defaultType = null;
|
boolean clearContent = false, headerStarted = false, headerEnded = false;
|
||||||
|
MPResultType defaultType = null;
|
||||||
|
|
||||||
//noinspection HardcodedLineSeparator
|
//noinspection HardcodedLineSeparator
|
||||||
for (final String line : CharStreams.readLines( reader ))
|
for (final String line : CharStreams.readLines( reader ))
|
||||||
// Header delimitor.
|
// Header delimitor.
|
||||||
if (line.startsWith( "##" )) {
|
if (line.startsWith( "##" )) {
|
||||||
if (!headerStarted)
|
if (!headerStarted)
|
||||||
// Starts the header.
|
// Starts the header.
|
||||||
headerStarted = true;
|
headerStarted = true;
|
||||||
else
|
else
|
||||||
// Ends the header.
|
// Ends the header.
|
||||||
headerEnded = true;
|
headerEnded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comment.
|
// Comment.
|
||||||
else if (line.startsWith( "#" )) {
|
else if (line.startsWith( "#" )) {
|
||||||
if (headerStarted && !headerEnded) {
|
if (headerStarted && !headerEnded) {
|
||||||
// In header.
|
// In header.
|
||||||
Matcher headerMatcher = headerFormat.matcher( line );
|
Matcher headerMatcher = headerFormat.matcher( line );
|
||||||
if (headerMatcher.matches()) {
|
if (headerMatcher.matches()) {
|
||||||
String name = headerMatcher.group( 1 ), value = headerMatcher.group( 2 );
|
String name = headerMatcher.group( 1 ), value = headerMatcher.group( 2 );
|
||||||
if ("Format".equalsIgnoreCase( name ))
|
if ("Format".equalsIgnoreCase( name ))
|
||||||
importFormat = ConversionUtils.toIntegerNN( value );
|
importFormat = ConversionUtils.toIntegerNN( value );
|
||||||
else if ("Passwords".equalsIgnoreCase( name ))
|
else if ("Passwords".equalsIgnoreCase( name ))
|
||||||
clearContent = "visible".equalsIgnoreCase( value );
|
clearContent = "visible".equalsIgnoreCase( value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// No comment.
|
// No comment.
|
||||||
else if (headerEnded) {
|
else if (headerEnded) {
|
||||||
Matcher siteMatcher = unmarshallFormats[importFormat].matcher( line );
|
Matcher siteMatcher = unmarshallFormats[importFormat].matcher( line );
|
||||||
if (!siteMatcher.matches()) {
|
if (!siteMatcher.matches()) {
|
||||||
logger.wrn( "Couldn't parse line: %s, skipping.", line );
|
logger.wrn( "Couldn't parse line: %s, skipping.", line );
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPFileSite site;
|
||||||
|
switch (importFormat) {
|
||||||
|
case 0:
|
||||||
|
site = new MPFileSite( user, //
|
||||||
|
siteMatcher.group( 5 ), MPAlgorithm.Version.fromInt( ConversionUtils.toIntegerNN(
|
||||||
|
colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(),
|
||||||
|
user.getAlgorithm().mpw_default_counter(),
|
||||||
|
MPResultType.forType( ConversionUtils.toIntegerNN( siteMatcher.group( 3 ) ) ),
|
||||||
|
clearContent? null: siteMatcher.group( 6 ),
|
||||||
|
null, null, null, ConversionUtils.toIntegerNN( siteMatcher.group( 2 ) ),
|
||||||
|
MPConstants.dateTimeFormatter.parseDateTime( siteMatcher.group( 1 ) ).toInstant() );
|
||||||
|
if (clearContent)
|
||||||
|
site.setSitePassword( site.getResultType(), siteMatcher.group( 6 ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
site = new MPFileSite( user, //
|
||||||
|
siteMatcher.group( 7 ), MPAlgorithm.Version.fromInt( ConversionUtils.toIntegerNN(
|
||||||
|
colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(),
|
||||||
|
UnsignedInteger.valueOf( colon.matcher( siteMatcher.group( 5 ) ).replaceAll( "" ) ),
|
||||||
|
MPResultType.forType( ConversionUtils.toIntegerNN( siteMatcher.group( 3 ) ) ),
|
||||||
|
clearContent? null: siteMatcher.group( 8 ),
|
||||||
|
MPResultType.GeneratedName, clearContent? null: siteMatcher.group( 6 ), null,
|
||||||
|
ConversionUtils.toIntegerNN( siteMatcher.group( 2 ) ),
|
||||||
|
MPConstants.dateTimeFormatter.parseDateTime( siteMatcher.group( 1 ) ).toInstant() );
|
||||||
|
if (clearContent) {
|
||||||
|
site.setSitePassword( site.getResultType(), siteMatcher.group( 8 ) );
|
||||||
|
site.setLoginName( MPResultType.StoredPersonal, siteMatcher.group( 6 ) );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new MPMarshalException( "Unexpected format: " + importFormat );
|
||||||
|
}
|
||||||
|
|
||||||
|
user.addSite( site );
|
||||||
}
|
}
|
||||||
|
|
||||||
MPFileSite site;
|
if (user == null)
|
||||||
switch (importFormat) {
|
throw new MPMarshalException( "No full header found in import file." );
|
||||||
case 0:
|
}
|
||||||
site = new MPFileSite( user, //
|
|
||||||
siteMatcher.group( 5 ), MPAlgorithm.Version.fromInt( ConversionUtils.toIntegerNN(
|
|
||||||
colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(),
|
|
||||||
user.getAlgorithm().mpw_default_counter(),
|
|
||||||
MPResultType.forType( ConversionUtils.toIntegerNN( siteMatcher.group( 3 ) ) ),
|
|
||||||
clearContent? null: siteMatcher.group( 6 ),
|
|
||||||
null, null, null, ConversionUtils.toIntegerNN( siteMatcher.group( 2 ) ),
|
|
||||||
MPConstants.dateTimeFormatter.parseDateTime( siteMatcher.group( 1 ) ).toInstant() );
|
|
||||||
if (clearContent)
|
|
||||||
site.setSitePassword( site.getResultType(), siteMatcher.group( 6 ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
site = new MPFileSite( user, //
|
|
||||||
siteMatcher.group( 7 ), MPAlgorithm.Version.fromInt( ConversionUtils.toIntegerNN(
|
|
||||||
colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(),
|
|
||||||
UnsignedInteger.valueOf( colon.matcher( siteMatcher.group( 5 ) ).replaceAll( "" ) ),
|
|
||||||
MPResultType.forType( ConversionUtils.toIntegerNN( siteMatcher.group( 3 ) ) ),
|
|
||||||
clearContent? null: siteMatcher.group( 8 ),
|
|
||||||
MPResultType.GeneratedName, clearContent? null: siteMatcher.group( 6 ), null,
|
|
||||||
ConversionUtils.toIntegerNN( siteMatcher.group( 2 ) ),
|
|
||||||
MPConstants.dateTimeFormatter.parseDateTime( siteMatcher.group( 1 ) ).toInstant() );
|
|
||||||
if (clearContent) {
|
|
||||||
site.setSitePassword( site.getResultType(), siteMatcher.group( 8 ) );
|
|
||||||
site.setLoginName( MPResultType.StoredPersonal, siteMatcher.group( 6 ) );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new MPMarshalException( "Unexpected format: " + importFormat );
|
|
||||||
}
|
|
||||||
|
|
||||||
user.addSite( site );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
throw new MPMarshalException( "No full header found in import file." );
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setComplete();
|
user.setComplete();
|
||||||
user.endChanges();
|
user.endChanges();
|
||||||
|
@ -60,10 +60,10 @@ public class MPJSONFile extends MPJSONAnyObject {
|
|||||||
objectMapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NON_PRIVATE );
|
objectMapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NON_PRIVATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPJSONFile() {
|
MPJSONFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPJSONFile(final MPFileUser modelUser)
|
MPJSONFile(final MPFileUser modelUser)
|
||||||
throws MPAlgorithmException, MPKeyUnavailableException {
|
throws MPAlgorithmException, MPKeyUnavailableException {
|
||||||
|
|
||||||
// Section: "export"
|
// Section: "export"
|
||||||
@ -135,7 +135,7 @@ public class MPJSONFile extends MPJSONAnyObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPFileUser readUser(final File file) {
|
MPFileUser readUser(final File file) {
|
||||||
MPAlgorithm algorithm = ifNotNullElse( user.algorithm, MPAlgorithm.Version.CURRENT ).getAlgorithm();
|
MPAlgorithm algorithm = ifNotNullElse( user.algorithm, MPAlgorithm.Version.CURRENT ).getAlgorithm();
|
||||||
|
|
||||||
return new MPFileUser(
|
return new MPFileUser(
|
||||||
@ -147,10 +147,8 @@ public class MPJSONFile extends MPJSONAnyObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readSites(final MPFileUser user)
|
void readSites(final MPFileUser user)
|
||||||
throws MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
|
throws MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
|
||||||
user.ignoreChanges();
|
|
||||||
|
|
||||||
for (final Map.Entry<String, Site> siteEntry : sites.entrySet()) {
|
for (final Map.Entry<String, Site> siteEntry : sites.entrySet()) {
|
||||||
String siteName = siteEntry.getKey();
|
String siteName = siteEntry.getKey();
|
||||||
Site fileSite = siteEntry.getValue();
|
Site fileSite = siteEntry.getValue();
|
||||||
@ -184,9 +182,6 @@ public class MPJSONFile extends MPJSONAnyObject {
|
|||||||
|
|
||||||
user.addSite( site );
|
user.addSite( site );
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setComplete();
|
|
||||||
user.endChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Data
|
// -- Data
|
||||||
|
@ -56,7 +56,11 @@ public class MPJSONUnmarshaller implements MPUnmarshaller {
|
|||||||
throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
|
throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
objectMapper.readValue( user.getFile(), MPJSONFile.class ).readSites( user );
|
user.ignoreChanges();
|
||||||
|
if (user.getFile().exists())
|
||||||
|
objectMapper.readValue( user.getFile(), MPJSONFile.class ).readSites( user );
|
||||||
|
user.setComplete();
|
||||||
|
user.endChanges();
|
||||||
}
|
}
|
||||||
catch (final JsonParseException e) {
|
catch (final JsonParseException e) {
|
||||||
throw new MPMarshalException( "Couldn't parse JSON.", e );
|
throw new MPMarshalException( "Couldn't parse JSON.", e );
|
||||||
|
Loading…
Reference in New Issue
Block a user