Skip to content

Commit

Permalink
Pastebin based Upload and required Settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Dec 11, 2017
1 parent f880c74 commit 5a4dac6
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 123 deletions.
Expand Up @@ -26,10 +26,11 @@
import mod.chiselsandbits.network.packets.PacketUndo;
import mod.chiselsandbits.network.packets.WriteBlueprintPacket;
import mod.chiselsandbits.share.ShareGenerator;
import mod.chiselsandbits.share.output.ClipBoardText;
import mod.chiselsandbits.share.output.ClipboardText;
import mod.chiselsandbits.share.output.IShareOutput;
import mod.chiselsandbits.share.output.LocalPNGFile;
import mod.chiselsandbits.share.output.LocalTextFile;
import mod.chiselsandbits.share.output.PasteBin;
import mod.chiselsandbits.voxelspace.IVoxelSrc;
import mod.chiselsandbits.voxelspace.VoxelCompressedProviderWorld;
import mod.chiselsandbits.voxelspace.VoxelOffsetRegion;
Expand Down Expand Up @@ -413,9 +414,12 @@ private void beginCapture(
case IMAGE_FILE_WITH_SCREENSHOT:
out = new LocalPNGFile( newFileName( ChiselsAndBits.getConfig().getShareFileOutputFolder(), ".png" ) );
break;
case TEXT_PASTEBIN:
out = new PasteBin();
break;
default:
case TEXT_CLIPBOARD:
out = new ClipBoardText();
out = new ClipboardText();
break;
case TEXT_FILE:
out = new LocalTextFile( newFileName( ChiselsAndBits.getConfig().getShareFileOutputFolder(), ".txt" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mod/chiselsandbits/commands/Share.java
Expand Up @@ -3,7 +3,7 @@
import javax.swing.JFileChooser;

import mod.chiselsandbits.share.ShareGenerator;
import mod.chiselsandbits.share.output.ClipBoardText;
import mod.chiselsandbits.share.output.ClipboardText;
import mod.chiselsandbits.share.output.IShareOutput;
import mod.chiselsandbits.share.output.LocalPNGFile;
import mod.chiselsandbits.share.output.LocalTextFile;
Expand Down Expand Up @@ -80,7 +80,7 @@ else if ( end == null )
else if ( start != null && end != null )
{
final World clientWorld = Minecraft.getMinecraft().theWorld;
IShareOutput out = new ClipBoardText();
IShareOutput out = new ClipboardText();

if ( args.length > 0 )
{
Expand Down
@@ -0,0 +1,16 @@
package mod.chiselsandbits.config;

public enum EnumPasteBinPrivacyMode
{
PUBLIC( "0" ),
UNLISTED( "1" ),
PRIVATE( "2" );

public final String value;

private EnumPasteBinPrivacyMode(
String v )
{
value = v;
}
}
Expand Up @@ -4,5 +4,6 @@ public enum EnumShareOutput
{
TEXT_CLIPBOARD,
TEXT_FILE,
TEXT_PASTEBIN,
IMAGE_FILE_WITH_SCREENSHOT
}
21 changes: 19 additions & 2 deletions src/main/java/mod/chiselsandbits/config/ModConfig.java
Expand Up @@ -153,12 +153,24 @@ public class ModConfig extends Configuration
@Configured( category = "Client Settings" )
public float radialMenuVolume;

@Configured( category = "Client Settings" )
@Configured( category = "Blueprint Settings" )
public EnumShareOutput shareOutput;

@Configured( category = "Client Settings" )
@Configured( category = "Blueprint Settings" )
public String shareFileOutputFolder;

@Configured( category = "Blueprint Settings" )
public String pasteBinAPIKey;

@Configured( category = "Blueprint Settings" )
public String pasteBinUsername;

@Configured( category = "Blueprint Settings" )
public String pasteBinPassword;

@Configured( category = "Blueprint Settings" )
public EnumPasteBinPrivacyMode pasteBinPrivacyMode;

public String getShareFileOutputFolder()
{
File f = new File( shareFileOutputFolder );
Expand Down Expand Up @@ -449,6 +461,11 @@ private void setDefaults()
ShowBitsInJEI = false;
enableVivecraftCompatibility = false;
enableMCMultipart = true;

pasteBinAPIKey = "";
pasteBinUsername = "";
pasteBinPassword = "";
pasteBinPrivacyMode = EnumPasteBinPrivacyMode.UNLISTED;
}

public ModConfig(
Expand Down
Expand Up @@ -46,6 +46,7 @@ public enum LocalStrings implements ILocalizeable
ShareNoFile( "help.share.nofile" ),
ShareInvalidData( "help.share.invaliddata" ),
ShareNoUrl( "help.share.badurl" ),
ShareURL( "help.share.url" ),

HelpPositivePrint( "help.positiveprint" ),
LongHelpPositivePrint( "help.positiveprint.long" ),
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/mod/chiselsandbits/share/ShareWorldData.java
Expand Up @@ -6,9 +6,13 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;

import org.apache.commons.lang3.StringEscapeUtils;

import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
Expand Down Expand Up @@ -92,17 +96,33 @@ public ShareWorldData(
{
final String header = "[C&B](";
final String footer = ")[C&B]";
final String htmlHeader = "[C&B]";

// is it html encoded? if it is decode the page before moving on.
if ( data.indexOf( htmlHeader ) != -1 )
{
data = StringEscapeUtils.unescapeHtml4( data );
}

int start = data.indexOf( header );
final int end = data.indexOf( footer );
int start = -1;
int end = -1;

// find a valid pattern in side...
Pattern p = Pattern.compile( "\\[C&B\\]\\([A-Za-z0-9+/=\n\r ]+\\)\\[C&B\\]" );
Matcher m = p.matcher( data );
if ( m.find() )
{
start = m.start();
end = m.end();
}

if ( start == -1 || end == -1 )
{
throw new IOException( "Unable to locate C&B Data." );
}

start += header.length();
data = data.substring( start, end );
data = data.substring( start, end - footer.length() );
final byte[] compressed = Base64.getDecoder().decode( data );
readCompressed( compressed );
}
Expand Down
103 changes: 0 additions & 103 deletions src/main/java/mod/chiselsandbits/share/output/ClipboardImage.java

This file was deleted.

Expand Up @@ -11,7 +11,7 @@
import mod.chiselsandbits.localization.LocalizedMessage;
import net.minecraft.client.gui.GuiScreen;

public class ClipBoardText implements IShareOutput
public class ClipboardText implements IShareOutput
{

String text;
Expand All @@ -21,12 +21,7 @@ public LocalizedMessage handleOutput(
final byte[] compressedData,
final BufferedImage screenshot ) throws UnsupportedEncodingException, IOException
{
final StringBuilder o = new StringBuilder();
o.append( "[C&B](" );
o.append( Base64.getEncoder().encodeToString( compressedData ) );
o.append( ")[C&B]" );
GuiScreen.setClipboardString( text = o.toString() );

GuiScreen.setClipboardString( text = getShareString( compressedData ) );
return new LocalizedMessage( LocalStrings.ShareClipboard );
}

Expand All @@ -47,4 +42,14 @@ public BlueprintData getData()
return bpd;
}

public static String getShareString(
byte[] compressedData )
{
final StringBuilder o = new StringBuilder();
o.append( "[C&B](" );
o.append( Base64.getEncoder().encodeToString( compressedData ) );
o.append( ")[C&B]" );
return o.toString();
}

}
Expand Up @@ -6,7 +6,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;

import mod.chiselsandbits.blueprints.BlueprintData;
import mod.chiselsandbits.localization.LocalStrings;
Expand All @@ -30,9 +29,7 @@ public LocalizedMessage handleOutput(
final BufferedImage screenshot ) throws UnsupportedEncodingException, IOException
{
final FileOutputStream o = new FileOutputStream( outFile );
o.write( new String( "[C&B](" ).getBytes( encoding ) );
o.write( Base64.getEncoder().encodeToString( compressedData ).getBytes( encoding ) );
o.write( new String( ")[C&B]" ).getBytes( encoding ) );
o.write( ClipboardText.getShareString( compressedData ).getBytes( encoding ) );
o.close();

return new LocalizedMessage( LocalStrings.ShareFile, outFile );
Expand Down

0 comments on commit 5a4dac6

Please sign in to comment.