เอกสาร Steamworks
Creating and using InstallScripts

ภาพรวม

แม้ว่า Steam จะสามารถติดตั้ง redistributables ทั่วไป มากมายได้โดยอัตโนมัติ แต่แอปพลิเคชันของคุณก็อาจจะมีข้อกำหนดในการใช้งานครั้งแรกอย่างอื่นอยู่
หมายเหตุ: ฟังก์ชันการทำงานของสคริปต์ติดตั้งที่ได้ระบุไว้ด้านล่างนี้มีไว้สำหรับระบบปฏิบัติการ Windows เป็นหลัก การรองรับ macOS จะถูกจำกัดไว้เแค่เพียงสิทธิ์ และ symlinks ของไฟล์เท่านั้น ในขณะนี้ยังไม่มีฟังก์ชันการทำงานของสคริปต์ติดตั้งระบบ Linux/SteamOS

ไฟล์สคริปต์ติดตั้ง คือ ไฟล์การกำหนดค่าสำหรับเรียกใช้การดำเนินการบางอย่างขณะติดตั้ง

เกมตัวเต็ม/แอปพลิเคชัน และแพ็คเกจเนื้อหาดาวน์โหลดอาจจะมีสคริปต์ติดตั้งได้ทั้งคู่ หากคุณได้ ประสานสคริปต์ติดตั้งของคุณไว้ในบิลด์ของคุณ คุณอาจจะมีสคริปต์ติดตั้งจำนวนเท่าใดก็ได้ สำหรับแอป SteamPlay ขอแนะนำให้คุณใช้ดีโปเฉพาะ OS ของคุณที่บรรจุสคริปต์ติดตั้งของคุณเอาไว้ตลอดเวลา

ตัวอย่าง

ตัวอย่างแบบพื้นฐานจะมีรูปแบบประมาณนี้:
"InstallScript" { "Registry" { "HKEY_LOCAL_MACHINE\\SOFTWARE\\Foo\\Bar" { "string" { "Install_Path" "%INSTALLDIR%" "Exe_Path" "%INSTALLDIR%\\foobar.exe" } "dword" { "PatchVersion" "12" } } } "Run Process" { "DirectX" { "HasRunKey" "HKEY_LOCAL_MACHINE\\Software\\Valve\\Steam\\Apps\\480" "Process 1" "%INSTALLDIR%\\DirectX\\DXSETUP.exe" "Command 1" "/silent" "NoCleanUp" "1" } } }

ชื่อคีย์ที่ 2 ต่อจากรูทจะอธิบายถึงประเภทการดำเนินการที่จะเกิดขึ้น

หมายเหตุ: ชื่อคีย์และค่าทั้งหมดจะสามารถใช้ Escape Sequences ได้ ดังนั้น หากคุณใช้ \ กรุณาทำเป็น \\

การประสานสคริปต์ติดตั้งไว้ในบิลด์ของคุณ

เริ่มแรก ไฟล์สคริปต์ติดตั้งจะต้องเป็นส่วนหนึ่งของดีโปที่ได้ติดตั้งไว้กับตัวบิลด์ดังกล่าว กรุณาตรวจสอบให้มั่นใจว่าไฟล์ดังกล่าวได้อยู่ใน ContentRoot ของแอปหรือดีโปที่ได้ให้นิยามไว้

จากนั้น ทำเครื่องหมายสคริปต์ติดตั้งโดยการใช้คำสั่ง InstallScript ในสคริปต์ของบิลด์ดีโป คุณสามารถดูตัวอย่างได้ที่หน้า การอัปโหลดไปยัง Steam - สคริปต์สำหรับบิลด์ขั้นสูง

ในระหว่างกระบวนการบิลด์ จะมีสองสิ่งเกิดขึ้น:
  • สคริปต์ติดตั้งจะถูกอัปโหลดไปยัง Steam และถูกลงนามเข้ารหัสไว้ Steam จะตรวจสอบความถูกต้องของลายเซ็นก่อนเริ่มดำเนินการการสคริปต์ติดตั้งนั้น ๆ และจำเป็นจะต้องดำเนินการบางอย่าง ซึ่งรวมถึงการเขียนไปยัง HKLM hive บน Windows ซึ่งอาจจะทำให้สำเนาภายในเครื่องของสคริปต์ติดตั้งของคุณถูกแก้ไขได้
  • สคริปต์ติดตั้งจะถูกทำเครื่องหมายในมานิเฟสต์ดีโป ซึ่งคุณสามารถดูได้ในไฟล์ manifest.txt ที่ถูกสร้างขึ้นเป็น a 100 ในช่องข้อความ แฟล็ก
เมื่อผู้ใช้ Steam เริ่มเปิดเกม Steam จะสแกนดีโปทั้งหมดที่เชื่อมต่ออยู่สำหรับเกมนั้น เพื่อหาไฟล์ใดก็ตามที่มีแฟล็กสคริปต์ติดตั้งแล้วเรียกใช้ไฟล์ดังกล่าว

รีจิสทรี

คำสั่งรีจิสทรีจะอนุญาตให้คุณสร้างหรือแก้ไขค่ารีจิสทรีของสตริงและ dword ได้ คีย์ใด ๆ ที่อยู่ใต้ชื่อคีย์ "รีจิสทรี" จะถูกปฏิบัติว่าเป็นเส้นทางแบบเต็มไปยังคีย์รีจิสทรีที่คุณต้องการจะสร้างหรือเปิด ภายใต้คีย์ดังกล่าว ให้ระบุคีย์ "สตริง" หรือ "dword" ชื่อคีย์และค่าใดก็ตามที่จัดเก็บไว้ในคีย์ "สตริง" หรือ "dword" จะเป็นชื่อรีจิสทรีและค่าที่ตั้งค่าไว้
ในการตั้ง ค่าเริ่มต้น ให้กับคีย์รีจิสทรี คุณควรจะใส่ชื่อคีย์เป็น (เริ่มต้น)

คำสั่ง Run Process

คำสั่ง Run Process จะอนุญาตให้แอปพลิเคชันของคุณเรียกใช้โปรแกรมได้ก่อนที่ผู้ใช้งานจะเปิดเกมของคุณขึ้นมาเป็นครั้งแรก
ในการพิจารณาว่าจำเป็นจะต้องใช้โปรแกรมในการเรียกใช้หรือไม่ สคริปต์ติดตั้งจะมองหาชื่อคีย์ (ที่เป็นค่า DWORD ในรีจิสทรี) ที่อยู่ในค่า HasRunKey หากค่าดังกล่าวไม่มีอยู่ หรือมีค่าเป็น 0 ก็จะเรียก CreateProcess ในค่า processXX/commandXX หาก CreateProcess ล้มเหลว จะมีการเรียก ShellExecuteEx หาก ExitCode ของโปรแกรมเป็น 0 สคริปต์ติดตั้งจะถือว่าประสบความสำเร็จและจะเขียนชื่อคีย์ของคุณเป็น 1 ลงในรีจิสทรี

ลูกค้าของ Steam ชอบการติดตั้งที่ทั้งรวดเร็วและไม่รบกวนการใช้งานอื่น ๆ เพิ่มพารามิเตอร์ silent หรือ quiet ลงในคำสั่ง Run Process ทั้งหมด และเพิ่มเฉพาะสิ่งที่เกมของคุณจำเป็นต้องใช้จริง ๆ เท่านั้น
คีย์/ค่าของ Run Process ที่จำเป็นต้องใช้คือ:
  • Process 1 - เส้นทางที่นำไปสู่โปรแกรมที่คุณต้องการจะเรียกใช้
คีย์/ค่าของ Run Process ที่สามารถเลือกใช้ ได้แก่:
  • Command 1 - Optional command you want to pass to the program.
  • HasRunKey - Optional registry key to check that the prereq is already installed.
  • NoCleanUp - Optional flag, when set install script will not delete the keyname when your app is deleted from Steam.
  • MinimumHasRunValue - Optional, sets the minimum value the install script should check for when determining to launch the program.
  • Requirement_OS - Optional key to apply OS requirements. See OS Specific Requirements for more details.
  • AsCurrentUser - Optional flag, set it to 1 if it's important for that program to run as the current user. Otherwise, the Steam client might run it as Administrator to avoid elevation prompts in Big Picture or VR environments.

Firewall Exceptions

หากเกมของคุณจำเป็นจะต้องใช้การเชื่อมต่อทางเครือข่ายใด ๆ ก็ตาม ให้ใช้ข้อยกเว้นของไฟร์วอลล์เพื่อมอบสิทธิ์ข้อยกเว้นของไฟร์วอลล์ใน Windows โดยอัตโนมัติโดยที่ไม่จำเป็นต้องบังคับให้ผู้ใช้ต้องยอมรับข้อยกเว้น
"Firewall" { "Space War Game" "%INSTALLDIR%\\SpaceWar.exe" }

OS Specific Requirements

ค่า Requirement_OS จะพร้อมใช้งานในการเรียกใช้การติดตั้งต่าง ๆ ในเวอร์ชัน/SKU ของ OS หลาย ๆ ประเภท ซึ่งจำเป็นต้องใช้กลุ่มคีย์ใหม่ที่เรียกว่า Requirement_OS จากนั้นจะต้องใช้ค่าคีย์เพิ่มเติมที่จับคู่ไว้ภายใน ตัวเลือก OS ที่สามารถใช้งานได้ระบุไว้ด้านล่างนี้
  • Is64BitWindows - ระบุว่ากระบวนการจะทำงานบนระบบปฏิบัติการเวอร์ชัน 64 บิตเท่านั้น ค่าที่สามารถระบุได้คือ 0 หรือ 1
  • OSType - ระบุว่ากระบวนการจะทำงานบนระบบปฏิบัติการเวอร์ชันตามที่ได้ระบุไว้เท่านั้น ค่าที่สามารถระบุได้คือ:
    • Windows 3.11
    • Windows 95
    • Windows 98
    • Windows ME
    • Windows NT
    • Windows 2000
    • Windows XP
    • Windows 2003
    • Windows Vista
    • Windows 7
    • Windows 2008
    • Windows 2012
    • Windows 2012 R2
    • Windows 8
    • Windows 8.1
    • Windows 10

ตัวอย่าง 64 บิต
ตัวอย่างดังต่อไปนี้จะเรียกใช้ตัวติดตั้งที่เหมาะสมให้แก่ตัวติดตั้งประเภท 32 หรือ 64 บิต
"Net32" { "Process 1" "%INSTALLDIR%\\redist\\Controller\\32bitInstaller.exe" "NoCleanUp" "1" "Requirement_OS" { "Is64BitWindows" "0" } } "Net64" { "Process 1" "%INSTALLDIR%\\redist\\Controller\\64bitInstaller.exe" "NoCleanUp" "1" "Requirement_OS" { "Is64BitWindows" "1" } }

ตัวอย่างประเภทระบบปฏิบัติการ
ตัวอย่างนี้จะสามารถทำงานบน Windows XP เท่านั้น

"Controller" { "Process 1" "%INSTALLDIR%\\redist\\WinXPInstaller.exe" "NoCleanUp" "1" "Requirement_OS" { "OSType" "Windows XP" } }

ตัวแปรสภาพแวดล้อม

ตัวแปรแวดล้อมได้รับการรองรับในสคริปต์ติดตั้ง All of the standard environment variables available on Windows can be used, along with a few others specific to an install script. ได้แก่
  • %INSTALLDIR% - เส้นทางเต็มที่ได้ติดตั้งแอปพลิเคชันไว้ โดยไม่ใส่เครื่องหมาย backslash
  • %ROOTDRIVE%0> - ตัวอักษรระบุไดรฟ์ที่ได้ติดตั้งแอปพลิเคชันไว้ เช่น C
  • %APPDATA% - โฟลเดอร์ \Users\username\AppData\
  • %USER_MYDOCS% - ใช้เพื่อเรียกรับโฟลเดอร์ user\My Documents
  • %COMMON_MYDOCS% - ใช้เพื่อเรียกรับโฟลเดอร์ All Users\Documents
  • %LOCALAPPDATA% - โฟลเดอร์ \Documents and Settings\username\Local Settings\Application Data (เฉพาะบนระบบ Vista ขึ้นไปเท่านั้น)
  • %WinDir% - ไดเรกทอรีการติดตั้งระบบ Windows
  • %STEAMPATH% - เส้นทางเต็มไปยังไดเรกทอรีการติดตั้งไคลเอนต์ Steam

Note that these are common paths, but they can be different based on what version of Windows the user is running.

ค่าเฉพาะภาษา

Both string and DWORD values can be assigned different data depending on what language the user is running Steam in. To use, create a subkey in the "string" or "dword" key with the name of the language, then assign the names and values in there. For example:
"InstallScript" { "Registry" { "HKEY_LOCAL_MACHINE\\SOFTWARE\\MonkeyDime Studios\\Killer Banana Peel" { "dword" { "english" { "Language" "1" } "french" { "Language" "2" } "german" { "Language" "3" } "italian" { "Language" "4" } "spanish" { "Language" "5" } } } } }

The install script gets the language from Steam's registry key, querying the value "Language". If that value isn't found then "english" is the default.

การถอนการติดตั้งแอป

When a user deletes or verifies your app from Steam, install scripts will be called to remove any registry values it created. The install script will also remove the value used to determine if a program should execute from Run Process, so that it can execute the next time your app runs (unless the NoCleanUp flag is set).

คำสั่ง Run Process ในการถอนการติดตั้ง

If you need to run any process at the time your app is uninstalled, add this to the install script. Please do not uninstall common redists such as DirectX, msvc run time, etc, as they are likely to be used by other games. This is only intended for game specific uninstall processes.
หมายเหตุ: Run Process On Uninstall will also be called when a user verifies the app in Steam. Do not run a process that will delete all files, as this will cause Steam to redownload everything during a verify.
"InstallScript" { "Run Process On Uninstall" { "Process_name" { "Process 1" "process.exe" "Command 1" "/command" } } }

คำถามที่พบบ่อย

ถาม: ทำไมสคริปต์ติดตั้งของฉันถึงเรียกใช้ Redistributable ของฉันในทุกครั้งที่ฉันเปิดเกมขึ้นมา?
ตอบ: This typically means that the redist is returning a non-zero return code. Steam checks that the return code is zero. If it sees that the return code is zero, it marks the redist as installed and doesn't run it again. If it returns any other value, Steam will attempt to run it again on next launch.

To fix this examine your redistributable paths and parameters. Some redists will return non-zero values if they already exist on the machine. This can often be fixed by using the redist's silent or quiet flag.

ถาม: ทำไมถึงไม่มีการเขียนคีย์รีจิสทรีของฉัน?
ตอบ: Typically this is because the install script isn't signed and you're writing to HKLM.
See the section on build integration, and ensure that a "kvsignatures" key was added to your script during the build, as Steam requires this signing to be completed to write to HKLM.

This can also be caused by the Windows 64 bit virtualization on 64 bit Windows, Steam writes to the Wow6432Node path in the registry.

ถาม: ทำไมสคริปต์ติดตั้งของฉันถึงดูเหมือนจะไม่ยอมทำงานเลย?
ตอบ: Please double check that your configuration is properly prepared.

ถาม: How do I add macOS redistributables? Why doesn't Run Process work in my macOS install script?
ตอบ: We don't currently have support for installing Mac redistributables. You will need to put the installer into your main executable.