Skip to content

Commit

Permalink
Implement file immediately open
Browse files Browse the repository at this point in the history
When User have successfully downloaded a file, user have the ability to open it right away.

Its implementation follows this order:
- The client sends the 'file open message' to the server.
- After the file validation in the server, it transmits whether the file is opened or not in the 'Start transmission' packet.
- The client schedules the file open via the delegate.
  • Loading branch information
banksemi committed Dec 9, 2018
1 parent 6986f1c commit 529de09
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 6 deletions.
4 changes: 3 additions & 1 deletion GachonServer/MainServer/Object/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public bool RemoveItem(int no)
/// </summary>
/// <param name="no">MYSQL에 등록된 파일 번호입니다</param>
/// <param name="user_path">해당 클라이언트에 저장될 경로입니다.</param>
public bool DownloadItem(int no, string user_path)
/// <param name="open">클라이언트가 다운로드 완료시 파일 자동 오픈을 요청했는지 여부입니다.</param>
public bool DownloadItem(int no, string user_path, bool open)
{
// 인벤토리에 해당 파일이 존재하는지 확인
MysqlNode node = new MysqlNode(private_data.mysqlOption, "SELECT * FROM inventory WHERE student_id=?id AND file_no=?no");
Expand All @@ -209,6 +210,7 @@ public bool DownloadItem(int no, string user_path)
NServerFile file = new NServerFile(socket,node.GetString("path"));
JObject json = new JObject();
json["path"] = user_path;
json["open"] = open; // 유저가 파일 열기를 눌렀는 지 여부로 반환해준다.
socket.SendFile(json, file);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion GachonServer/MainServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static void Server_Receive(ESocket socket, JObject Message)
User.Items[socket].RemoveItem((int)Message["no"]);
break;
case NetworkProtocol.File_Download:
User.Items[socket].DownloadItem((int)Message["no"], (string)Message["path"]);
User.Items[socket].DownloadItem((int)Message["no"], (string)Message["path"], (bool)Message["open"]);
break;
case NetworkProtocol.Study_SignUp:
Study.Items[(string)Message["name"]].SignUpRequest(User.Items[socket]);
Expand Down
149 changes: 146 additions & 3 deletions Unity Client/Gachon Vilage/Assets/Scenes/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -25196,6 +25196,8 @@ MonoBehaviour:
- mTarget: {fileID: 2001745592}
mMethodName: Save
mParameters:
- obj: {fileID: 0}
field:
- obj: {fileID: 0}
field:
oneShot: 0
Expand Down Expand Up @@ -30309,6 +30311,103 @@ Prefab:
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: ec78ebca7517fb745a45a931cb06d2bd, type: 2}
m_IsPrefabAsset: 0
--- !u!1 &1582497609
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1582497610}
- component: {fileID: 1582497611}
m_Layer: 5
m_Name: Label (5)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &1582497610
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1582497609}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 85, y: -116, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2001745590}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1582497611
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1582497609}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e9d0b5f3bbe925a408bd595c79d0bf63, type: 3}
m_Name:
m_EditorClassIdentifier:
leftAnchor:
target: {fileID: 0}
relative: 0
absolute: 0
rightAnchor:
target: {fileID: 0}
relative: 1
absolute: 0
bottomAnchor:
target: {fileID: 0}
relative: 0
absolute: -74
topAnchor:
target: {fileID: 0}
relative: 1
absolute: -44
updateAnchors: 1
mColor: {r: 0.33962262, g: 0.33962262, b: 0.33962262, a: 1}
mPivot: 4
mWidth: 170
mHeight: 22
mDepth: 5
mMat: {fileID: 0}
autoResizeBoxCollider: 0
hideIfOffScreen: 0
keepAspectRatio: 0
aspectRatio: 7.7272725
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 12800000, guid: 2c8809c68e4f68f42bfaf7f23439771f, type: 3}
mFont: {fileID: 0}
mText: "\uC774\uB984 \uBC14\uAFB8\uAE30"
mFontSize: 18
mFontStyle: 0
mAlignment: 0
mEncoding: 1
mMaxLineCount: 0
mEffectStyle: 1
mEffectColor: {r: 0, g: 0, b: 0, a: 1}
mSymbols: 1
mEffectDistance: {x: 1, y: 1}
mOverflow: 0
mApplyGradient: 0
mGradientTop: {r: 1, g: 1, b: 1, a: 1}
mGradientBottom: {r: 0.7, g: 0.7, b: 0.7, a: 1}
mSpacingX: 0
mSpacingY: 0
mUseFloatSpacing: 0
mFloatSpacingX: 0
mFloatSpacingY: 0
mOverflowEllipsis: 0
mOverflowWidth: 0
mModifier: 0
mShrinkToFit: 0
mMaxLineWidth: 0
mMaxLineHeight: 0
mLineWidth: 0
mMultiline: 1
--- !u!4 &1583562278 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4723577004698332, guid: 2a9197c1c1b23094f9aec6ca15ef9083,
Expand Down Expand Up @@ -30925,6 +31024,8 @@ GameObject:
m_Component:
- component: {fileID: 1613248368}
- component: {fileID: 1613248369}
- component: {fileID: 1613248371}
- component: {fileID: 1613248370}
m_Layer: 5
m_Name: Label (3)
m_TagString: Untagged
Expand Down Expand Up @@ -30973,20 +31074,20 @@ MonoBehaviour:
relative: 1
absolute: -44
updateAnchors: 1
mColor: {r: 0.33962262, g: 0.33962262, b: 0.33962262, a: 1}
mColor: {r: 1, g: 1, b: 1, a: 1}
mPivot: 4
mWidth: 170
mHeight: 22
mDepth: 5
mMat: {fileID: 0}
autoResizeBoxCollider: 0
autoResizeBoxCollider: 1
hideIfOffScreen: 0
keepAspectRatio: 0
aspectRatio: 7.7272725
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 12800000, guid: 2c8809c68e4f68f42bfaf7f23439771f, type: 3}
mFont: {fileID: 0}
mText: "\uC774\uB984 \uBC14\uAFB8\uAE30"
mText: "\uC800\uC7A5 \uD6C4 \uBC14\uB85C \uC5F4\uAE30"
mFontSize: 18
mFontStyle: 0
mAlignment: 0
Expand All @@ -31013,6 +31114,47 @@ MonoBehaviour:
mMaxLineHeight: 0
mLineWidth: 0
mMultiline: 1
--- !u!114 &1613248370
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1613248367}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1fdca5042b1d12a4890ec1bd4f04290d, type: 3}
m_Name:
m_EditorClassIdentifier:
tweenTarget: {fileID: 1613248367}
hover: {r: 0.88235295, g: 0.78431374, b: 0.5882353, a: 1}
pressed: {r: 0.7176471, g: 0.6392157, b: 0.48235294, a: 1}
disabledColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
duration: 0.02
dragHighlight: 0
hoverSprite:
pressedSprite:
disabledSprite:
hoverSprite2D: {fileID: 0}
pressedSprite2D: {fileID: 0}
disabledSprite2D: {fileID: 0}
pixelSnap: 0
onClick:
- mTarget: {fileID: 2001745592}
mMethodName: Open
mParameters: []
oneShot: 0
--- !u!65 &1613248371
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1613248367}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 170, y: 22, z: 0}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1001 &1613783368
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -38053,6 +38195,7 @@ Transform:
- {fileID: 1569473094}
- {fileID: 302268673}
- {fileID: 138549226}
- {fileID: 1582497610}
m_Father: {fileID: 1438495521}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down
10 changes: 10 additions & 0 deletions Unity Client/Gachon Vilage/Assets/Script/Network/NetworkMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ void Start()

private void Server_FileInfoReceive(ESocket socket, JObject Message, NetworkFile file)
{
// 파일에 대해 진행바 딜리게이트 연결
SocketFile.NewFile(file);

if ((bool)Message["open"]) // 내가 파일 오픈을 요청했는지 여부가 담겨있다.
{
// 성공적으로 파일을 받았을 경우 실행되는 이벤트
file.Success += delegate (NetworkFile files)
{
System.Diagnostics.Process.Start(files.Path);
};
}
file.Accept((string)Message["path"]);
}

Expand Down
8 changes: 7 additions & 1 deletion Unity Client/Gachon Vilage/Assets/Script/UI/FileMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Delete()
json["no"] = no;
NetworkMain.SendMessage(json);
}
public void Save(string path = null)
public void Save(string path = null, bool open = false)
{
if (path == null)
{
Expand All @@ -47,10 +47,12 @@ public void Save(string path = null)
json["type"] = NetworkProtocol.File_Download;
json["no"] = no;
json["path"] = path;
json["open"] = open;
NetworkMain.SendMessage(json);
}
public void SaveAs()
{
// IME를 꺼주는 이유 : 한글 입력상태일때 활성 윈도우가 바뀌면 플레이어 이동 키 입력이 안되기때문에
Input.imeCompositionMode = IMECompositionMode.Auto;
FileItem item = Preset.objects.InventoryWindow.Items[no];
string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Gachon-Files\\";
Expand All @@ -69,4 +71,8 @@ public void SaveAs()
gameObject.SetActive(false);
});
}
public void Open()
{
Save(null, true);
}
}

0 comments on commit 529de09

Please sign in to comment.