GW2RegisterLicenceFile
GW2RegisterLicenceFile ใช้ลงทะเบียนไฟล์ licence กับเซสชันหนึ่งรายการ
หากไม่มีการลงทะเบียนทั้ง GW2RegisterLicenceFile หรือ GW2RegisterLicenceMemory กับเซสชัน Editor จะพยายามค้นหา licence ในตำแหน่งเริ่มต้น โดยเป็นไฟล์ชื่อ gwkey.lic ที่อยู่ในโฟลเดอร์เดียวกับไลบรารีของ Editor หากไม่พบ ไลบรารีจะถือว่าไม่มี licence และบางกระบวนการอาจล้มเหลวเนื่องจากปัญหา licence หมดอายุ
- C++
- C#
- Java
- Python
- JavaScript
สรุป
ฟังก์ชัน GW2RegisterLicenceFile จะร้องขอให้เซสชัน session ใช้ licence ที่ระบุไว้ในไฟล์ซึ่งมีชื่อเป็นสตริงที่ filename ชี้อยู่ Licence นี้จะถูกนำไปใช้กับการประมวลผลทั้งหมดที่ Glasswall ดำเนินการสำหรับเซสชันนั้น
#include "glasswall.core2.api.h"
int GW2RegisterLicenceFile(Session session, const char *filename);
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงล้มเหลว
ตัวอย่าง
#include "glasswall.core2.api.h"
HANDLE session = GW2OpenSession();
if (!session)
/* deal with error */
else
if (GW2RegisterLicenceFile(session, "gwkey.lic") < 0)
/* deal with error */
else
/* the file has been successfully registered */
...
/* later */
if (GW2CloseSession(session) < 0)
/* error closing session */
สรุป
เมธอด RegisterLicenceFile จะร้องขอให้เซสชัน session ใช้ licence ที่ระบุไว้ในไฟล์ซึ่งมีชื่อเป็นสตริงที่ filename ชี้อยู่ Licence นี้จะถูกนำไปใช้กับการประมวลผลทั้งหมดที่ Glasswall ดำเนินการสำหรับเซสชันนั้น
/// <param name="session">Current open Glasswall session</param>
/// <param name="filePath">The file path to the licence file to be registered</param>
public int RegisterLicenceFile(int session, string filePath)
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงล้มเหลว
สรุป
import com.glasswall.core2javabridge.*;
public int GW2RegisterLicenceFile(int session, String licenceFilePath) throws GlasswallException, NullPointerException
(Deprecated)
public int GW2RegisterLicenceFile(int session, byte[] licenceFilePath) throws GlasswallException, NullPointerException
หมายเหตุ
พารามิเตอร์ของฟังก์ชัน GW2RegisterLicenceFile ได้รับการอัปเดตให้ใช้ String แทน byte[] แล้ว ฟังก์ชันเดิมถูกเลิกใช้งานแล้ว
ส่งกลับ
ฟังก์ชัน GW2RegisterLicenceFile จะส่งกลับค่า enumeration GW2_RetStatus ที่แปลงเป็น int ค่าเป็นลบหมายความว่าเกิดข้อผิดพลาด 0 หมายถึงสำเร็จ โปรดดูรายละเอียดใน API Overview/Return types
จะมีการโยนข้อยกเว้น NullPointerException หาก licenceFilePath เป็น null หรือว่างเปล่า
จะมีการโยนข้อยกเว้น GlasswallException หาก session ไม่ถูกต้อง หากไม่สามารถดึง licenceFilePath ได้ หรือหากไม่สามารถแปลง licenceFilePath เป็น UTF-8 ได้
การลงทะเบียน licence สำหรับแต่ละเซสชันจะถูกจัดการโดยอัตโนมัติใน Python wrapper และผู้ใช้ไม่จำเป็นต้องเรียก GW2RegisterLicenceFile หรือ GW2RegisterLicenceMemory ด้วยตนเอง
โดยค่าเริ่มต้น คลาส Editor คาดว่าจะมีไฟล์ licence ที่ถูกต้องอยู่ในไดเรกทอรีเดียวกับ library_path คุณยังสามารถระบุพาธอื่นไปยังไฟล์ licence gwkey.lic ได้โดยใช้ argument licence
import glasswall
# Load the Glasswall Editor library with a specified licence file
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0", licence=r"C:\gwpw\licence\gwkey.lic")
อีกทางเลือกหนึ่ง คุณสามารถส่งข้อมูล licence ในหน่วยความจำเป็นออบเจ็กต์ bytes, bytearray หรือ io.BytesIO ได้
import glasswall
# Alternatively, load the licence from in-memory bytes or bytearray
with open(r"C:\gwpw\licence\gwkey.lic", "rb") as f:
licence_data = f.read()
editor = glasswall.Editor(
r"C:\gwpw\libraries\10.0",
licence=licence_data # In-memory licence data
)
สรุป
เมธอด RegisterLicenceFile จะร้องขอให้เซสชัน session ใช้ licence ที่ระบุไว้ในไฟล์ซึ่งมีชื่อเป็นสตริงที่ filename ชี้อยู่ Licence นี้จะถูกนำไปใช้กับการประมวลผลทั้งหมดที่ Glasswall ดำเนินการสำหรับเซสชันนั้น
/**
* Sets what licence file should be loaded for the session.
* @param {number} session The ID of the session.
* @param {string} filename The filename from which to load the licence.
* @returns {number} Status of the operation; 0 for success, non-zero for failure.
*/
GW2RegisterLicenceFile(session, filename)
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงล้มเหลว