チェンジセット 3580

差分発生行の前後
無視リスト:
コミット日時:
2010/03/22 01:11:08 (3 年前)
コミッタ:
hkrn
ログメッセージ:

implemented loading and saving data provisionally

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/gunyarapaint/branches/gunyarapaint/compat/.actionScriptProperties

    r3510 r3580  
    1313      <libraryPathEntry kind="1" linkType="1" path="libs"/> 
    1414      <libraryPathEntry kind="3" linkType="1" path="/framework/bin/framework.swc" useDefaultLinkType="false"/> 
     15      <libraryPathEntry kind="3" linkType="1" path="C:/Users/hkrn/Documents/Projects/resources/as3crypto.swc" useDefaultLinkType="false"/> 
    1516    </libraryPath> 
    1617    <sourceAttachmentPath/> 
  • as3/gunyarapaint/branches/gunyarapaint/compat/src/gunyarapaint.mxml

    r3578 r3580  
    1414    <mx:Script> 
    1515        <![CDATA[ 
     16            import com.hurlant.crypto.Crypto; 
     17            import com.hurlant.crypto.symmetric.ICipher; 
     18            import com.hurlant.crypto.symmetric.IVMode; 
     19            import com.hurlant.crypto.symmetric.PKCS5; 
     20             
    1621            import mx.controls.Alert; 
    1722            import mx.core.UITextField; 
     
    3439            import org.libspark.gunyarapaint.ui.v1.MovableCanvasModule; 
    3540             
     41            private var m_bytes:ByteArray; 
    3642            private var m_recorder:Recorder; 
    3743            private var m_context:CanvasModuleContext; 
     
    149155            } 
    150156             
    151             public function deserialize(s:String):void 
    152             { 
    153                 // TODO: 実装 
    154                 // var log:GPLogger = GPLogger.deserialize(s); 
     157            public function load(bytes:ByteArray, password:String):void 
     158            { 
     159                var passwordBytes:ByteArray = new ByteArray(); 
     160                bytes.position = 0; 
     161                bytes.endian = Endian.BIG_ENDIAN; 
     162                passwordBytes.writeUTFBytes(password); 
     163                var cipher:ICipher = Crypto.getCipher("aes", passwordBytes, new PKCS5()); 
     164                try { 
     165                    var ivMode:IVMode = IVMode(cipher); 
     166                    var ivBytes:ByteArray = ByteArray(bytes.readObject()); 
     167                    var dataBytes:ByteArray = ByteArray(bytes.readObject()); 
     168                    ivMode.IV = ivBytes; 
     169                    cipher.decrypt(dataBytes); 
     170                    dataBytes.inflate(); 
     171                    dataBytes.readBytes(m_bytes); 
     172                    // TODO: 実装 
     173                    // var log:GPLogger = GPLogger.deserialize(s); 
     174                } 
     175                catch (e:Error) { 
     176                    trace(e.message); 
     177                    Alert.show("指定されたファイルからログを復元することが出来ませんでした", ALERT_TITLE); 
     178                } 
     179            } 
     180             
     181            public function save(bytes:ByteArray, password:String):void 
     182            { 
     183                var dataBytes:ByteArray = new ByteArray(); 
     184                var passwordBytes:ByteArray = new ByteArray(); 
     185                bytes.endian = Endian.BIG_ENDIAN; 
     186                passwordBytes.writeUTFBytes(password); 
     187                dataBytes.writeBytes(m_bytes); 
     188                dataBytes.deflate(); 
     189                var cipher:ICipher = Crypto.getCipher("aes", passwordBytes, new PKCS5()); 
     190                cipher.encrypt(dataBytes); 
     191                bytes.writeObject(IVMode(cipher).IV); 
     192                bytes.writeObject(dataBytes); 
     193                bytes.position = 0; 
    155194            } 
    156195             
     
    179218                undoBufferSize = int(parameters['undoBufferSize']); 
    180219                 
    181                 var bytes:ByteArray = new ByteArray(); 
    182                 m_recorder = Recorder.create(bytes, width, height, undoBufferSize); 
     220                m_bytes = new ByteArray(); 
     221                m_recorder = Recorder.create(m_bytes, width, height, undoBufferSize); 
    183222                m_context = new CanvasModuleContext(m_recorder); 
    184223                m_module = m_context.getModule(FreeHandModule.FREE_HAND); 
  • as3/gunyarapaint/branches/gunyarapaint/compat/src/org/libspark/gunyarapaint/ui/v1/DataController.mxml

    r3578 r3580  
    11<?xml version="1.0" encoding="utf-8"?> 
    22<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="346" title="ふっかつのじゅもん"> 
     3    <mx:Script> 
     4        <![CDATA[ 
     5            import mx.controls.Alert; 
     6            import mx.core.Application; 
     7            import mx.managers.PopUpManager; 
     8             
     9            private static const ALERT_TITLE:String = "ふっかつのじゅもん"; 
     10             
     11            public function set password(value:String):void 
     12            { 
     13                passwordTextArea.text = value; 
     14            } 
     15             
     16            private function onClipboard():void 
     17            { 
     18                System.setClipboard(passwordTextArea.text); 
     19            } 
     20             
     21            private function onSave():void 
     22            { 
     23                if (passwordTextArea.text.length > 0) { 
     24                    var bytes:ByteArray = new ByteArray(); 
     25                    Application.application.save(bytes, passwordTextArea.text); 
     26                    createFileReferenceEvents(); 
     27                    m_file.addEventListener(Event.SELECT, onSelectSave); 
     28                    m_file.addEventListener(Event.COMPLETE, onSaveComplete); 
     29                    m_file.save(bytes); 
     30                } 
     31                else { 
     32                    Alert.show("パスワードが入力されていません", ALERT_TITLE); 
     33                } 
     34            } 
     35             
     36            private function onLoad():void 
     37            { 
     38                if (passwordTextArea.text.length > 0) { 
     39                    createFileReferenceEvents(); 
     40                    m_file.addEventListener(Event.SELECT, onSelectLoad); 
     41                    m_file.addEventListener(Event.COMPLETE, onLoadComplete); 
     42                    m_file.browse(); 
     43                } 
     44                else { 
     45                    Alert.show("パスワードが入力されていません", ALERT_TITLE); 
     46                } 
     47            } 
     48             
     49            private function onSelectLoad(event:Event):void 
     50            { 
     51                var file:FileReference = FileReference(event.target); 
     52                file.load(); 
     53                currentState = "progress"; 
     54            } 
     55             
     56            private function onSelectSave(event:Event):void 
     57            { 
     58                currentState = "progress"; 
     59            } 
     60             
     61            private function onLoadComplete(event:Event):void 
     62            { 
     63                var file:FileReference = FileReference(event.target); 
     64                var bytes:ByteArray = file.data; 
     65                currentState = ""; 
     66                Application.application.load(bytes, passwordTextArea.text); 
     67                removeFileReference(); 
     68            } 
     69             
     70            private function onSaveComplete(event:Event):void 
     71            { 
     72                currentState = ""; 
     73                removeFileReference(); 
     74            } 
     75             
     76            private function onCancel(event:Event):void 
     77            { 
     78                removeFileReference(); 
     79            } 
     80             
     81            private function onProgress(event:ProgressEvent):void 
     82            { 
     83                progress.setProgress(event.bytesLoaded, event.bytesTotal); 
     84            } 
     85             
     86            private function onError(event:ErrorEvent):void 
     87            { 
     88                Alert.show(event.text, ALERT_TITLE); 
     89                removeFileReference(); 
     90            } 
     91             
     92            private function createFileReferenceEvents():void 
     93            { 
     94                m_file = new FileReference(); 
     95                m_file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); 
     96                m_file.addEventListener(IOErrorEvent.IO_ERROR, onError); 
     97                m_file.addEventListener(ProgressEvent.PROGRESS, onProgress); 
     98                m_file.addEventListener(Event.CANCEL, onCancel); 
     99            } 
     100             
     101            private function removeFileReference():void 
     102            { 
     103                m_file.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); 
     104                m_file.removeEventListener(IOErrorEvent.IO_ERROR, onError); 
     105                m_file.removeEventListener(ProgressEvent.PROGRESS, onProgress); 
     106                m_file.removeEventListener(Event.CANCEL, onCancel); 
     107                m_file.removeEventListener(Event.SELECT, onSelectLoad); 
     108                m_file.removeEventListener(Event.SELECT, onSelectSave); 
     109                m_file.removeEventListener(Event.COMPLETE, onLoadComplete); 
     110                m_file.removeEventListener(Event.COMPLETE, onSaveComplete); 
     111                m_file = null; 
     112                PopUpManager.removePopUp(this); 
     113            } 
     114             
     115            private var m_file:FileReference; 
     116        ]]> 
     117    </mx:Script> 
     118    <mx:states> 
     119        <mx:State name="progress"> 
     120            <mx:SetProperty target="{progress}" name="visible" value="true"/> 
     121        </mx:State> 
     122    </mx:states> 
    3123    <mx:TextArea id="passwordTextArea" x="0" y="0" width="380" height="266" verticalScrollPolicy="on"/> 
    4     <mx:Button id="setClipboardButton" x="10" y="274" label="クリップボードにコピー" click="copyToClipboard()"/> 
    5     <mx:Button id="deserializeButton" x="7" y="138" label="ふっかつする" click="deserialize()"/> 
    6     <mx:Script> 
    7         import flash.system.System; 
    8          
    9         import mx.core.Application; 
    10         import mx.managers.PopUpManager; 
    11          
    12         import org.libspark.gunyarapaint.ui.v1.Canvas; 
    13          
    14         public function set password(s:String):void { 
    15             passwordTextArea.text = s; 
    16         } 
    17         public function copyToClipboard():void { 
    18             System.setClipboard(passwordTextArea.text); 
    19         } 
    20         public function deserialize():void { 
    21             Application.application.deserialize(passwordTextArea.text); 
    22             PopUpManager.removePopUp(this); 
    23         } 
    24     </mx:Script> 
     124    <mx:Button id="setClipboardButton" x="124.5" y="274" label="クリップボードにコピー" click="onClipboard()"/> 
     125    <mx:Button id="deserializeButton" x="10" y="274" label="ふっかつする" click="onLoad()"/> 
     126    <mx:Button x="290" y="274" label="ほぞんする" click="onSave()"/> 
     127    <mx:ProgressBar x="10" y="238" width="360" enabled="true" id="progress" visible="false"/> 
    25128</mx:TitleWindow>